I pull out the data from mysql in datagridview. and double clicking on the line draws a new window with detailed info. but the same doubleclick works on the column header and passes the selected string to the method. How to prevent double click on the title?

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e){ var o=sender as DataGridViewCell; if (!(o is DataGridViewHeaderCell)){} //не работает } 

    1 answer 1

    For the header, the RowIndex property of the DataGridViewCellEventArgs is -1, respectively, you can check these properties, and based on this, do or not do something:

     private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) return; //тут что-то делаем }