Skip to main content

Custom Detail Descriptions

The DataGridDetailDescription class provides information about a detail relation whose content will be displayed as the details of the data items in a grid or another detail. By default, detail descriptions are automatically created for:

  • every DataRelation in a DataTable (DataRelationDetailDescription)
  • data items that implement the IEnumerable interface (EnumerableDetailDescription)
  • data items that implement the IListSource interface (ListSourceDetailDescription)
  • every EntityCollection<TEntity> exposed by a data item (EntityDetailDescription)

Detail descriptions can also be explicitly defined by adding them to DetailDescriptions collection of their parent DataGridCollectionView, DataGridCollectionViewSource, or detail description.

Although the most common types of detail relations are automatically detected, it is also possible to create and use custom detail descriptions that will return detail items for a parent item, whatever the definition of the detail relation is.

Creating a Detail Description

Custom detail descriptions can be created by deriving from the DataGridDetailDescription class and overriding the GetDetailsForParentItem method to return the appropriate detail items, as an IEnumerable, for the received parent item (see Example 1). In the case where there are no detail items for a parent item, an empty IEnumerable or null (Nothing in Visual Basic) must be returned.

If a detail description requires information that cannot be provided through XAML, such as a PropertyDescriptor, the Initialize method can be overridden and the information provided.

Examples

All examples in this topic assume that the grid is bound to the Employees table of a LINQ data context, unless stated otherwise.

Example 1: Creating a custom detail description

The following example demonstrates how to create and use a custom detail description that handles LINQ detail relations, which are provided by properties to which the AssociationAttribute is applied.

<Grid>
<Grid.Resources>
<xcdg:DataGridCollectionViewSource x:Key="cvs_employees"
Source="{Binding Source={x:Static Application.Current},
Path=LinqDataContext.Employees}">
<xcdg:DataGridCollectionViewSource.DetailDescriptions>
<local:LinqToSqlDetailDescription RelationName="Employee_Employees"
Title="Employees" />
<local:LinqToSqlDetailDescription RelationName="Employee_Customer"
Title="Customers">
<local:LinqToSqlDetailDescription.DetailDescriptions>
<local:LinqToSqlDetailDescription RelationName="Customer_Order"
Title="Orders">
<local:LinqToSqlDetailDescription.DetailDescriptions>
<local:LinqToSqlDetailDescription RelationName="Order_Order_Detail"
Title="Order Details" />
</local:LinqToSqlDetailDescription.DetailDescriptions>
</local:LinqToSqlDetailDescription>
</local:LinqToSqlDetailDescription.DetailDescriptions>
</local:LinqToSqlDetailDescription>
</xcdg:DataGridCollectionViewSource.DetailDescriptions>
</xcdg:DataGridCollectionViewSource>
</Grid.Resources>

<xcdg:DataGridControl x:Name="EmployeesGrid"
ItemsSource="{Binding Source={StaticResource cvs_employees}}"
ItemsSourceName="Employee Information"
AutoCreateDetailConfigurations="True" />
</Grid>