Xceed DataGrid for WPF v7.3 Documentation
Xceed.Wpf.DataGrid Assembly / Xceed.Wpf.DataGrid Namespace / DataGridDetailDescription Class
Members Example


In This Topic
    DataGridDetailDescription Class
    In This Topic
    The DataGridDetailDescription class provides information about a detail relation whose content will be displayed as the details of the master data items in a grid or as the data items of another detail.
    Syntax
    'Declaration
     
    <TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider)>
    <NameScopePropertyAttribute("NameScope", System.Windows.NameScope)>
    Public MustInherit Class DataGridDetailDescription 
       Inherits System.Windows.DependencyObject
    'Usage
     
    Dim instance As DataGridDetailDescription
    [TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]
    [NameScopeProperty("NameScope", System.Windows.NameScope)]
    public abstract class DataGridDetailDescription : System.Windows.DependencyObject 
    Example
    All examples in this topic assume that the grid is bound to the Employees table of a LINQ data context or Northwind database, unless stated otherwise.
    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.The following example demonstrates how to explicitly define detail descriptions for the DataRelations found in the DataTable to which the grid is bound and how to calculate statistical functions for a detail description whose results will be displayed in the StatRows contained in the footer sections of the details to which the description's corresponding detail configuration will be 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>
    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports Xceed.Wpf.DataGrid
    Imports System.Reflection
    Imports System.Data.Linq.Mapping
    Imports System.Diagnostics
    Imports System.Collections
    Namespace Xceed.Wpf.Documentation
      Public Class LinqToSqlDetailDescription
                   Inherits DataGridDetailDescription
        Protected Overrides Function GetDetailsForParentItem( ByVal parentCollectionView As DataGridCollectionView, _
                                                              ByVal parentItem As Object ) As IEnumerable
          Dim parentItemType As Type = parentItem.GetType()
          Dim foundProperty As PropertyInfo = Nothing
          Dim properties() As PropertyInfo = parentItemType.GetProperties()
          Dim propertyInfo As PropertyInfo
          For Each propertyInfo In properties
            Dim attributes() As Object = propertyInfo.GetCustomAttributes( Type.GetType( AssociationAttribute ), _
                                                                            False)
    
            If attributes.GetLength( 0 ) = 0 Then
              Continue
            End If
    
            Dim associationAttribute As AssociationAttribute = CType( attributes( 0 ), AssociationAttribute )
    
            If associationAttribute.Name = Me.RelationName Then
              foundProperty = propertyInfo
              Exit Property
            End If
          Next
    
          If foundProperty Is Nothing Then
            Return New Object()
          Else
            Dim details As Object = foundProperty.GetValue( parentItem, Nothing )
            Dim detailsType As Type = details.GetType()
            Dim getNewBindingList As MethodInfo = detailsType.GetMethod( "GetNewBindingList" )
    
            Return CType( getNewBindingList.Invoke( details, Nothing), IEnumerable )
          End If
        End Function
      End Class
    End Namespace
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Xceed.Wpf.DataGrid;
    using System.Reflection;
    using System.Data.Linq.Mapping;
    using System.Diagnostics;
    using System.Collections;
    namespace Xceed.Wpf.Documentation
    {
     public class LinqToSqlDetailDescription: DataGridDetailDescription
     {
       protected override IEnumerable GetDetailsForParentItem( DataGridCollectionView parentCollectionView,
                                                               object parentItem )
       {
         Type parentItemType = parentItem.GetType();
         PropertyInfo foundProperty = null;
        
         PropertyInfo[] properties = parentItemType.GetProperties();
         foreach( PropertyInfo propertyInfo in properties )
         {
           object[] attributes = propertyInfo.GetCustomAttributes( typeof( AssociationAttribute ), false );
           if( attributes.GetLength( 0 ) == 0 )
             continue;
           AssociationAttribute associationAttribute = ( AssociationAttribute )attributes[ 0 ];
           if( associationAttribute.Name == this.RelationName )
           {
             foundProperty = propertyInfo;
             break;
           }
         }
         if( foundProperty == null )
         {
           return new object[] { };
         }
         else
         {
           object details = foundProperty.GetValue( parentItem, null );
           Type detailsType = details.GetType();
           MethodInfo getNewBindingList = detailsType.GetMethod( "GetNewBindingList" );
    
           return ( IEnumerable )getNewBindingList.Invoke( details, null );
         }
       }
     }
    }
    <Grid>
      <Grid.Resources>
         <xcdg:DataGridCollectionViewSource x:Key="cvs_employees"
                                            Source="{Binding Source={x:Static Application.Current}, 
                                                             Path=Employees}">
    
           <xcdg:DataGridCollectionViewSource.DetailDescriptions>
              <xcdg:DataRelationDetailDescription RelationName="Employee_Orders"
                                                  Title="Employee Orders">
                 <xcdg:DataRelationDetailDescription.DetailDescriptions>
                    <xcdg:DataRelationDetailDescription RelationName="Order_OrderDetails"
                                                        Title="Order Details">
                       <xcdg:DataRelationDetailDescription.ItemProperties>
                          <xcdg:DataGridItemProperty Name="UnitPrice" />
                          <xcdg:DataGridItemProperty Name="Quantity" />
                          <xcdg:DataGridItemProperty Name="Discount" />
                       </xcdg:DataRelationDetailDescription.ItemProperties>
                       <xcdg:DataRelationDetailDescription.StatFunctions>                          
                          <xcdg:SumFunction ResultPropertyName="sum_quantity"
                                            SourcePropertyName="Quantity" />
                          <xcdg:AverageFunction ResultPropertyName="average_unitprice"
                                                SourcePropertyName="UnitPrice" />
                       </xcdg:DataRelationDetailDescription.StatFunctions>
                    </xcdg:DataRelationDetailDescription>
                 </xcdg:DataRelationDetailDescription.DetailDescriptions>
              </xcdg:DataRelationDetailDescription>
           </xcdg:DataGridCollectionViewSource.DetailDescriptions>
         </xcdg:DataGridCollectionViewSource>
      </Grid.Resources>
     
      <xcdg:DataGridControl x:Name="EmployeesGrid"
                          ItemsSource="{Binding Source={StaticResource cvs_employees}}"
                          ItemsSourceName="Employee Information"
                          AutoCreateDetailConfigurations="True">
    
        <xcdg:DataGridControl.DetailConfigurations>
           <xcdg:DetailConfiguration RelationName="Employee_Orders">
              <xcdg:DetailConfiguration.DetailConfigurations>
                 <xcdg:DetailConfiguration RelationName="Order_OrderDetails">
                    <xcdg:DetailConfiguration.Footers>
                       <DataTemplate>
                          <xcdg:StatRow Background="AliceBlue">
                             <xcdg:StatCell FieldName="UnitPrice"
                                            ResultPropertyName="average_unitprice"
                                            ResultConverterParameter="f2" />
                             <xcdg:StatCell FieldName="Quantity"
                                            ResultPropertyName="sum_quantity" />                             
                          </xcdg:StatRow>
                       </DataTemplate>
                    </xcdg:DetailConfiguration.Footers>
                 </xcdg:DetailConfiguration>
              </xcdg:DetailConfiguration.DetailConfigurations>
           </xcdg:DetailConfiguration>
         </xcdg:DataGridControl.DetailConfigurations>  
       </xcdg:DataGridControl>
    </Grid>
    Inheritance Hierarchy
    Public Properties
     NameDescription
    Public PropertyGets or sets a value indicating whether detail descriptions are to be automatically created.  
    Public PropertyGets a value indicating whether the foreign key descriptions are automatically created.  
    Public PropertyGets or sets a value indicating whether item properties are to be automatically created.  
    Public PropertyGets or sets a value indicating how automatic filtering of the data items in the detail will be performed.  
    Public PropertyGets a dictionary that contains a list of the detail's DataGridItemProperty objects with their corresponding auto-filter values.  
    Public PropertyGet or sets the default value of the CalculateDistinctValues property when a DataGridItemProperty has not explicitly set its value.  
    Public Property (Inherited from System.Windows.DependencyObject)
    Public PropertyGets a collection of DataGridDetailDescription objects that provide information on the details that will be contained in the detail, including sorting, grouping, and child detail descriptions.  
    Public Property (Inherited from System.Windows.Threading.DispatcherObject)
    Public PropertyGets or sets a value representing the constraint applied to the distinct values of the underlying DataGridCollectionView when automatically filtering data items.  
    Public PropertyGets or sets a value indicating how filters entered into a FilterRow are applied.  
    Public PropertyGets a collection of group descriptions that describe how the items in the detail are grouped.  
    Public Property (Inherited from System.Windows.DependencyObject)
    Public PropertyGets a collection of DataGridItemProperty objects, which represent the items that are contained in the detail.  
    Public PropertyGets or sets the relation name of the detail.  
    Public PropertyGets a collection of SortDescription objects that describe how the items in the collection are sorted in the detail.  
    Public PropertyGets a collection of the statistical functions whose results can be used by various elements throughout the detail.  
    Public PropertyGets or sets the title that can be used to provide a user-friendly name for the detail configuration associated with the detail description.  
    Public PropertyGets or sets the template that will be used to display the description's title.  
    Top
    Public Methods
    Protected Methods
     NameDescription
    Protected Internal MethodRetrieves the details for the specified parent data item.  
    Protected Internal MethodInitializes the detail using the information retrieved from the specified parent collection view.  
    Protected Method (Inherited from System.Windows.DependencyObject)
    Protected MethodInvoked whenever a WeakEventManager delivers the event being managed by the class.  
    Protected Internal Method (Inherited from System.Windows.DependencyObject)
    Top
    Extension Methods
     NameDescription
    Public Extension MethodOverloaded. 
    Top
    Requirements

    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

    See Also