Selects the appropriate detail configuration based on the specified information.
This example assumes that the grid is bound to the Orders table of the Northwind database.
The following example demonstrates how to create a custom detail-configuration selector that will return the appropriate detail configuration depending on the relation name, and in which a column is hidden and another is modified in its width and content alignment. The implementation of the OrdersDetailConfigurationSelector is provided below.
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
<Grid.Resources>
<xcdg:DataGridCollectionViewSource x:Key="cvsOrders"
Source="{Binding Source={x:Static Application.Current},Path=Orders}" />
<local:OrdersDetailConfigurationSelector x:Key="ordersDetailConfigurationSelector" />
</Grid.Resources>
<xcdg:DataGridControl x:Name="dataGrid"
ItemsSource="{Binding Source={StaticResource cvsOrders}}"
DetailConfigurationSelector="{StaticResource ordersDetailConfigurationSelector}" />
</Grid>
public class OrdersDetailConfigurationSelector : DetailConfigurationSelector
{
public override DetailConfiguration SelectDetailConfiguration( string relationName, DataGridDetailDescription dataGridDetailDescription )
{
var detailConfig = default( DetailConfiguration );
if( relationName == "OrdersOrderDetails" )
{
var discountColumn = new Column { FieldName = "Discount", Visible = false };
var unitPriceColumn = new Column { FieldName = "UnitPrice", Title = "Unit Price", Width = 60, CellHorizontalContentAlignment = HorizontalAlignment.Center };
detailConfig = new DetailConfiguration();
detailConfig.RelationName = relationName;
detailConfig.AutoCreateDetailConfigurations = true;
detailConfig.Columns.Add( discountColumn );
detailConfig.Columns.Add( unitPriceColumn );
}
return detailConfig;
}
}
Public Class OrdersDetailConfigurationSelector
Inherits DetailConfigurationSelector
Public Overrides Function SelectDetailConfiguration(ByVal relationName As String, ByVal dataGridDetailDescription As DataGridDetailDescription) As DetailConfiguration
Dim detailConfig = Nothing
If relationName = "OrdersOrderDetails" Then
Dim discountColumn = New Column With {.FieldName = "Discount", .Visible = False}
Dim unitPriceColumn = New Column With {.FieldName = "UnitPrice", .Title = "Unit Price", .Width = 60, .CellHorizontalContentAlignment = HorizontalAlignment.Center}
detailConfig = New DetailConfiguration()
detailConfig.RelationName = relationName
detailConfig.AutoCreateDetailConfigurations = True
detailConfig.Columns.Add(discountColumn)
detailConfig.Columns.Add(unitPriceColumn)
End If
Return detailConfig
End Function
End Class
Target Platforms: Windows 11, Windows, 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2