Definition
Change editted cell in datagridview on enter (vb.net). In which case the following edit cell would be the first cell in the following row. Navigating through. I should mention that if you are editing a cell the PreviewKeyDown event will not fire when the Enter key is pressed, but neither will the KeyPress event. That's because the text box that being used to edit the data in the DataGridView handles the keyboard input. You can attach a handler to that too, but it's a bit more work.
Commits and ends the edit operation on the current cell.
Overloads
EndEdit()EndEdit()EndEdit()EndEdit() | Commits and ends the edit operation on the current cell using the default error context. |
EndEdit(DataGridViewDataErrorContexts)EndEdit(DataGridViewDataErrorContexts)EndEdit(DataGridViewDataErrorContexts)EndEdit(DataGridViewDataErrorContexts) | Commits and ends the edit operation on the current cell using the specified error context. |
Commits and ends the edit operation on the current cell using the default error context.
Returns
true
if the edit operation is committed and ended; otherwise, false
.
Exceptions
The cell value could not be committed and either there is no handler for the DataError event or the handler has set the ThrowException property to true
.
Remarks
This method calls the EndEdit overload, passing in a bitwise combination of the Parsing and Commit values.
This method raises the CellEndEdit event.
This method may result in an exception if errors are not handled with the DataError event.
EndEdit(DataGridViewDataErrorContexts)EndEdit(DataGridViewDataErrorContexts)EndEdit(DataGridViewDataErrorContexts)EndEdit(DataGridViewDataErrorContexts)
Commits and ends the edit operation on the current cell using the specified error context.
Parameters
- context
- DataGridViewDataErrorContextsDataGridViewDataErrorContextsDataGridViewDataErrorContextsDataGridViewDataErrorContexts
A bitwise combination of DataGridViewDataErrorContexts values that specifies the context in which an error can occur.
Returns
true
if the edit operation is committed and ended; otherwise, false
.
Exceptions
The cell value could not be committed and either there is no handler for the DataError event or the handler has set the ThrowException property to true
.
Remarks
This method raises the CellEndEdit event.
This method may result in an exception if errors are not handled with the DataError event.
Applies to
I have a custom DataGridView control in a Windows-Forms application. When a user presses the Enter key, I do not want anything to happen. I have already overridden the OnKeyPress method in my custom DataGridView to prevent the SelectedCell property from changing. This works alright when a cell is selected but not being editted. However, if a cell is in Edit mode when Enter is pressed, the CellEndEdit event is still fired and the SelectedCell property is subsequently changed.
How can I stop the Enter key from ending Edit Mode on my DataGridView control?
1 Answer
I have found the answer, thanks to varocarbas, who commented below my original question. My assumption is that the CellEndEdit Event is fired somewhere following the ProcessCmdKeys() method-call but before the OnKeyPress() call due to the precedence of the ENTER key being higher than a normal key (it's a Command key). This explains why I was unable to change the behavior while a cell was still in EditMode using OnKeyPress().
The custom DataGridView that I created, which prevents any action from occurring following an ENTER-key press in a DataGridView, can be seen below:
Somebody please correct me if my assumption about the call-sequence is inadequate. Also note, this ProcessCmdKey() override made my previously mentioned override of the OnKeyPress() method unnecessary.