How to avoid selecting a particular column in WPF GridDataControl?
How to avoid selecting a particular column in GridDataControl?
GridDataControl allows you to select single or multiple records based on the value specified for the ListBoxSelectionMode property. By default GridDataControl does not avoids selecting any column, however you can achieve it in a different way. Using QueryCellInfo event you can able to get the index of the column(s) that you want to avoid selection. By setting the e.Style.Enable property as to ‘false’ for that column(s), you can deactivate the cells belonging to that column from being current cell. Thus you cannot select or edit that column.
Following code snippet example demonstrates how to avoid selection of the column with mapping name “EmpName”.
C#
dataGrid.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(OnQueryCellInfo); void OnQueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { var index = this.dataGrid.VisibleColumns.IndexOf(this.dataGrid.VisibleColumns.FirstOrDefault(x => x.MappingName == "EmpName")); var resolvedIndex = this.dataGrid.Model.ResolveVisibleColumnIndexToPosition(index); if (e.Style.ColumnIndex == resolvedIndex) { e.Style.Enabled = false; } }
Here the index of the column with MappingName “EmpName” in the DataGrid is obtained in the variable index. Using this index the current position of that column in the view is resolved using the method ResolveVisiblecolumnIndexToPosition. This allows you to locate that column in cases such as grouping and when row header is enabled. Thus you can disable the selection of that column using the obtained resolvedIndex.
Conclusion
I hope you enjoyed learning about how to avoid selecting a particular column in WPF GridDataControl.
You can refer to our WPF DataGrid feature tour
page to know about its
other groundbreaking feature representations. You can also explore our
WPF
DataGrid documentation
to
understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!