Answered DataGridViewTextBoxEditingControl

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
How can I catch the Keydown event in a DataGridViewTextBoxEditingControl?
I'm trying to shift the focus to the 1st cell in a row when the user enters a new row by pressing the Enter Key. This is easy if the cell is not in edit mode, but I can't seem to implement it when the cell is "dirty".
 
Last edited:
"Dirty" is not the correct terminology. "Dirty" indicates that the data in the cell has changed but has not yet been saved. What you mean is when the cell is in edit mode, i.e. has an embedded editing control.

You can handle the EditingControlShowing event of the grid to get access to the editing control when it is displayed. You can then attach one or more event handlers to it. Make sure you remove them when the editing session ends though.
 
OK, I'm able to trap most KeyDown events for the editing textbox control, except the Enter Key and the Tab Key. I image I need to override the IsInputKey function for the control... but maybe I'm making a bigger deal than it's worth here. Here's what I'm trying to accomplish: In a bound datagridview, when the user presses the Enter key, I want the focus to go to the 1st cell in the next row rather than just dropping down to the next row in the same column where the user finished input. The logical layout of the input begins with the 1st cell. Typically, people don't start their data entry in the middle of a record. Many users are also very accustomed to using the Enter Key when finishing input rather than the Tab key. Is there a simpler way to accomplish this?
 
You don't need to override IsInputKey. The PreviewKeyDown event was added in .NET 2.0 to provide similar functionality from the outside, so you could avoid having to create custom controls for just that purpose.
 
JM you are THE man!
This works! I've been screwing with this for the better part of the day!
I have a talent for over complicating things with vb...
Thank You!
 
Back
Top