How to hide the key mapping column in Details View in WPF DataGrid?
You can hide the key mapping column in DetailsView WPF DataGrid (column maps the parent and nested datagird) of detailsview datagrid by handling AutoGeneratingColumn event.
XAML
<syncfusion:SfDataGrid x:Name="dataGrid" ItemsSource="{Binding Path=OrdersDetails}"> <syncfusion:SfDataGrid.DetailsViewDefinition> <syncfusion:GridViewDefinition RelationalColumn="OrderDetails"> <syncfusion:GridViewDefinition.DataGrid> <syncfusion:SfDataGrid x:Name="detailsViewGrid" AutoGenerateColumns="True" /> </syncfusion:GridViewDefinition.DataGrid> </syncfusion:GridViewDefinition> </syncfusion:SfDataGrid.DetailsViewDefinition> </syncfusion:SfDataGrid>
C#
this.detailsViewGrid.AutoGeneratingColumn += detailsViewGrid_AutoGeneratingColumn; void detailsViewGrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e) { if (e.Column.MappingName == "OrderID") e.Cancel = true; }
If SfDataGrid.AutoGenerateRelations property is true, you can fire AutoGeneratingColumn event in SfDataGrid.AutoGeneratingRelations event.
C#
this.dataGrid.AutoGeneratingRelations += dataGrid_AutoGeneratingRelations; void dataGrid_AutoGeneratingRelations(object sender, AutoGeneratingRelationsArgs e) { e.GridViewDefinition.DataGrid.AutoGeneratingColumn += DataGrid_AutoGeneratingColumn; } void DataGrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e) { if (e.Column.MappingName == "OrderID") e.Cancel = true; }
Figure 1: Before hide the key mapping column of detailsviewdatagrid
Figure 2: After hide the key mapping column of detailsviewdatagrid
Sample Links:
Conclusion
I hope you enjoyed learning about how to hide key mapping column in WPF DetailsViewDataGrid | Syncfusion
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!