Consider 2 DataGridViews both with SelectionMode = RowHeaderSelect. In grid1 I have 2 columns; a TextBox and a CheckBox. In grid2 I have 2 columns; a ComboBox and a TextBox.
When I click on the RowHeader, the focus goes to the first cell, not the RowHeaderCell. When I press the DEL button, the contents of the cell is deleted (TextBox content is cleared and ComboBox is set to 1st item).
This way the UserDeletingRow event never fires as the DataGridView FAQ says "Users can delete rows only when the current cell is not in edit mode, the AllowUserToDeleteRows property is set to true".
As a workaround I implemented this code in RowHeaderMouseClick
grid.CurrentCell = grid.Rows[rowIndex].Cells[columnName];
grid.Rows[rowIndex].Selected = true;
In case of grid1 I pass the name of the CheckBox column and the UserDeletingRow event fires when I press DEL. However for grid2 passing the name of the ComboBox column doesn't fire the event.
I have tried the following:
1- Select RowHeaderCell -> Exception because it cannot be selected.
2- grid.EndEdit() -> No effect.
3- Change the SelectionMode to FullRowSelect then back to RowHeaderSelect -> Cell is set to edit mode.
My Question:
I need the UserDeletingRow to fire regardless of the column of the grid? Or a workaround to select the HeaderCell if possible?
Edit (Short form of the question):
Clicking the RowHeader selects the row and puts the first cell in edit mode, if applicable, this way clicking the DEL button deletes the cell contents and doesn't fire the UserDeletingRow event. As a workaround I select a cell, if available, that cannot be put in edit mode, e.g. CheckBoxColumn.
Is this the default behavior of clicking the RowHeader? If yes, can you show me a workaround? If no can you point me to the cause of this behavior?
Edit 2:
I have found that setting the EditMode to EditOnEnter makes clicking RowHeader put the first cell in edit mode. I will try to overcome this but any help is appreciated.