I'm working on a program with DataGridViews
.
In one DatagridView
there is a DataGridViewTextBoxColumn
, which is enabled to be edited by the user. When the user is done with typing the numbers into it, he presses ENTER on the keyboard. Now the DataGridView
does all its Events
, and after all Events
, the last thing is the problem.
Everything is done, and Windows is going to Select the next DataGridViewRow
, and I'm not able to prevent this.
I tried
if (e.KeyData == Keys.Enter) e.SuppressKeyPress = true; // or e.Handled
in nearly every event I found. Sadly I was only able to Prevent the ENTER key when the DataGridViewTextBoxColumn
is not in edit mode.
Heres my methode t find the ENTER while in Editing
Adding the Event
private void dgr_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
e.Control.KeyPress += new KeyPressEventHandler(dgr_KeyPress_NumericTester);
}
And this is the event to accept numeric input only.
private void dgr_KeyPress_NumericTester(object sender, KeyPressEventArgs e)
{
if (!Char.IsDigit(e.KeyChar) && e.KeyChar != 8) e.Handled = true;
}
To explain in detail:
When the user enters a Value, that has some dependings, I would like to give another control the focus, so he is used to correct the dependings.
I also tried it with DependingControl.Focus()
but the last "enter" is going to be the last thing on the view.
Does someone know how to prevent this?
ProcessCmdKey
, see [here for how](windowsclient.net/blogs/faqs/archive/2006/05/30/… ) and [here for why][2] [2]: blogs.msdn.com/b/jfoscoding/archive/2005/01/24/359334.aspx – Dibbuk