Category / Section
How to avoid selection in header cell of WPF GridControl?
1 min read
GridControl selects row or column or table when clicking header row and column cell. You can disable this selection behavior by handling GridControl.SelectionChanging event.
In the below code, Selection action cancelled when clicking over first header row and first header column.
C#
grid.SelectionChanging += Grid_SelectionChanging;
private void Grid_SelectionChanging(object sender, Syncfusion.Windows.Controls.Grid.GridSelectionChangingEventArgs e)
{
if (e.Range.Contains(GridRangeInfo.Row(0)) || e.Range.Contains(GridRangeInfo.Col(0)))
e.Cancel = true;
}
Disabling table selection when clicking topleft header cell
You can disable the table selection when clicking the topleft header cell by setting Cancel property to false of SelectionChangingEventArg of GridControl.SelectionChanging event.
C#
grid.SelectionChanging += Grid_SelectionChanging;
private void Grid_SelectionChanging(object sender, Syncfusion.Windows.Controls.Grid.GridSelectionChangingEventArgs e)
{
if (e.Range.Contains(GridRangeInfo.Row(0)) || e.Range.Contains(GridRangeInfo.Col(0)))
e.Cancel =false;
}
Sample: View sample in GitHub