You can handle the DataGrid's DoubleClick event, and use the HitTest method to test if the double-click was on a column header.
using System;
using System.Drawing;
using System.Windows.Forms;
private DataGrid dataGrid1;
// ...
dataGrid1.DoubleClick += new EventHandler( dataGrid1_DoubleClick );
// ...
private void dataGrid1_DoubleClick( object sender, EventArgs e )
{
Point point = dataGrid1.PointToClient( Cursor.Position );
DataGrid.HitTestInfo hti = dataGrid1.HitTest( point );
if ( hti.Type == DataGrid.HitTestType.ColumnHeader )
{
// process column header double-click...
string message = string.Format( "Column {0} header double-clicked",
hti.Column.ToString() );
MessageBox.Show( message );
}
}
Contributed from George Shepherd's Windows Forms FAQ