KeyDown Problem

Hello,
I want to capture special Keys from the DataGridView during EditMode (e.g. when the Caret is showing)

This was my first guess:

...somewhere in the code ...

dataGridViewSuche.EditingControl.KeyDown -= new KeyEventHandler(EditingControl_KeyDown);
dataGridViewSuche.EditingControl.KeyDown += new KeyEventHandler(EditingControl_KeyDown);

later...

private void EditingControl_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
BeginSearch(); // special Reaction to "Return"
e.Handled = true;
}
Console.WriteLine(e.KeyCode.ToString()); // just for looking....
}

As i understood, i can not get preprocessed charaters (like vk_return, vk_up ...) like this.

So i adapted a piece of Code made by Ken Tucker...

public override bool PreProcessMessage(ref Message msg)
{
Keys keyCode = (Keys)(int)msg.WParam & Keys.KeyCode;

// for a datagrid, we need to eat the tab key oe else its done twice
if((msg.Msg == WM_KEYDOWN)
&& keyCode == Keys.Enter)
{
...
}
}

It is the same reaction: i catch get the Keys.Enter only if the grid is not in Editing mode.
So i'll never get it if the DataGridViews EditMode is "EditOnEnter".

Any Ideas/Advice ?
Roland

[1365 byte] By [rschaeling] at [2007-12-24]
# 1
I guess when you are in edit mode, the message is sent to the cell. So you may try override the PreProcessMessage of cell class(if it exists).
WangChi at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2

I think you are going to have create a custom column for this. The editing control class has a EditingControlWantsInputKey function. If you return true for the key press the editing control handles the key. A return of false means the datagridview handles it. The datetimepicker custom cell example in the datagridview faq samples shows some sample code.

KenTucker at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3

rschaeling wrote:

Hi

I'm using textbox in VB.Net in Web Form.

As soon as i hit the enter key in textbox the control must be passed to the next button. How can i achieve this

Jackuline at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 4
What thread is that from?
KenTucker at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 5

Thank You. I found some Hooks by your hints and overriding...

/// <summary>

/// Konvertiert Enter zu Right-Key...

/// </summary>

/// <param name="keyData"></param>

/// <returns></returns>

protected override bool ProcessDialogKey(Keys keyData)

{

Keys key = (keyData & Keys.KeyCode);

if (key == Keys.Enter)

{

return this.ProcessRightKey(keyData);

}

return base.ProcessDialogKey(keyData);

}

protected override bool ProcessDataGridViewKey(KeyEventArgs e)

{

if (e.KeyCode == Keys.Enter)

{

return this.ProcessRightKey(e.KeyData);

}

return base.ProcessDataGridViewKey(e);

}

rschaeling at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...