C# – DataGridView item double click

cdatagridviewnetwinforms

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?

Best Answer

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.