views:

1210

answers:

2

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
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
+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