Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

5. Windows Forms Datagrid

5.10 How can I catch a double-click into a column header cell?


You can use the DataGrid's double-click event and its HitTest method to catch a double click on a header.

     private void dataGrid1_DoubleClick(object sender, System.EventArgs e)
     {
          System.Drawing.Point pt = dataGrid1.PointToClient(Cursor.Position);

          DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);

          if(hti.Type == DataGrid.HitTestType.ColumnHeader)
          {
               MessageBox.Show("double clicked clicked column header " + hti.Column.ToString());
          }
     }