I want to do some stuff while double click on a Gridview (Row) not single cell. Means on a double click event handler not on MouseDoubleClick event. But i am not able to disable the header column and row double click event..and also want to load data to combobox(ComboBox is on the same form) when i double click on the GridView Row. Help me Please..!!!
private void gvLoadAllData_DoubleClick(object sender, EventArgs e)
{
    if()
    {
        //Do Something
    }
}
                I already had CellDoubleClick event defined and doing stuff, my issue was that a double click on the header was firing that event and therefore crashing the app. 
Taking Disaster's idea, I just added the following to get around that event.
if (e.RowIndex == -1) 
    return;
                        DoubleClick on Row Header
To handle a double click on row header, handle RowHeaderMouseDoubleClick event of DataGridView:
private void dataGridView1_RowHeaderMouseDoubleClick(object sender, 
    DataGridViewCellMouseEventArgs e)
{
    var rowIndex = e.RowIndex;
    //You handled a double click on row header
    //Do what you need
}
DoubleClick on Column Header
To handle a double click on column header handle ColumnHeaderMouseDoubleClick event of DataGridView:
private void dataGridView1_ColumnHeaderMouseDoubleClick(object sender, 
    DataGridViewCellMouseEventArgs e)
{
    var columnIndex = e.ColumnIndex;
    //You handled a double click on column header
    //Do what you need
}
Using DoubleClick
Also if for any reason you want to use DoubleClick event, here is what you should write:
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
    var g = sender as DataGridView;
    if (g != null)
    {
        var p = g.PointToClient(MousePosition);
        var hti = g.HitTest(p.X, p.Y);
        if (hti.Type == DataGridViewHitTestType.ColumnHeader)
        {
            var columnIndex = hti.ColumnIndex;
            //You handled a double click on column header
            //Do what you need
        }
        else if (hti.Type == DataGridViewHitTestType.RowHeader)
        {
            var rowIndex = hti.RowIndex;
            //You handled a double click on row header
            //Do what you need
        }
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With