I have a DataGridView in a Windows Form. I want to handle double click events on each cell to display a detail form related to that record. Unfortunately, the double click event is executed when you double click on column headers. What should I do?
+2
A:
What event are you handling? Ideally you should handle the CellDoubleClick
or the CellMouseDoubleClick
events and opening your details form in that handler. The latter event will catch a Double click using any of the mouse buttons (the button can be queried using the MouseEventArgs.Button
property.
Cerebrus
2009-04-18 09:08:02
This doesn't solve the specific problem the OP mentioned at all: "Unfortunately, the double click event is executed when you double click on column headers"
Mehrdad Afshari
2009-04-18 14:58:42
+2
A:
You should check the RowIndex
and ColumnIndex
property of the event arguments. If one of them is negative, it means that either a row header or a column header is clicked, you should ignore that event.
Mehrdad Afshari
2009-04-18 14:59:35