datagrid, header, click

  • Thread starter Thread starter wooz
  • Start date Start date
W

wooz

How to read value of the clicked datagrid header. I can obtain only
information about column number of clicked header. Column header seams not
to be ordinary cell, so DataGrid.CurrentCell is usless in this case.
Any suggestions ?
 
information about column number of clicked header. Column header seams not

Sorry for my english. There should be ofcourse "seems" not "seams"
 
To test that user clicked on the header column you should use
dataGrid.HitTest method in DataGrid Click event handler:

Point p = dataGrid.PointToClient(Control.MousePosition);
DataGrid.HitTestInfo hti = dataGrid.HitTest(p.X, p.Y);
if (hti.Type == DataGrid.HitTestType.ColumnHeader)
{
MessageBox.Show("Clicked:" + hti.Column);
}

when you recieved column number you can get header text like this:

MessageBox.Show(dataGrid.TableStyles[0].GridColumnStyles[hti.Column].HeaderText);

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Back
Top