Data Dependent Details

  • 2 minutes to read

The GridControl allows you to display different details for different master rows without any additional coding.

The image below demonstrates the GridControl that displays a list of Subordinates for the Vice President and a list of Customers for Sales Representatives.

WPF_Grid_DataDependentDetail.png

The GridControl allows you to define a simple detail selection logic in XAML (using the DetailDescriptorSelector object) in the following way:

  1. Pass the DetailDescriptorSelector object to the GridControl.DetailDescriptor property.

    <dxg:GridControl ItemsSource="{x:Static local:ViewModel.Employees}">
        <dxg:GridControl.DetailDescriptor>
            <dxg:DetailDescriptorSelector>
                <!-- DetailDescriptorSelector -->
            </dxg:DetailDescriptorSelector>
        </dxg:GridControl.DetailDescriptor>
    </dxg:GridControl>
    
    NOTE

    The DetailDescriptorSelector can be bound only to a corresponding master row object's properties.

  2. The DetailDescriptorSelector selects a detail descriptor when a corresponding trigger condition is met.

    The code sample below demonstrates how to provide a detail descriptor that is selected for master rows that meet specific criteria (Employees.Count == 0 in this example).

    <dxg:GridControl ItemsSource="{x:Static local:ViewModel.Employees}">
        <dxg:GridControl.DetailDescriptor>
            <dxg:DetailDescriptorSelector>
                <!-- A detail descriptor selected for master rows, whose Employees.Count value is equal to 0 -->
                <dxg:DetailDescriptorTrigger Binding="{Binding Path=Employees.Count}" Value="0">
                    <dxg:DataControlDetailDescriptor ItemsSourcePath="Customers">
                        <dxg:GridControl>
                            <!-- The detail GridControl settings -->
                        </dxg:GridControl>
                    </dxg:DataControlDetailDescriptor>
                </dxg:DetailDescriptorTrigger>
            </dxg:DetailDescriptorSelector>
        </dxg:GridControl.DetailDescriptor>
        <!-- The master GridControl settings -->
    </dxg:GridControl>
    
  3. To provide a default detail descriptor, pass the DataControlDetailDescriptor with the configured detail GridControl to the DetailDescriptorSelector.DefaultValue property.

    <dxg:GridControl ItemsSource="{x:Static local:ViewModel.Employees}">
        <dxg:GridControl.DetailDescriptor>
            <dxg:DetailDescriptorSelector>
    
                <!-- The default detail descriptor -->
                <dxg:DetailDescriptorSelector.DefaultValue>
                    <dxg:DataControlDetailDescriptor ItemsSourcePath="Employees">
                        <dxg:GridControl>
                            <!-- The default detail GridControl settings -->
                        </dxg:GridControl>
                    </dxg:DataControlDetailDescriptor>
                </dxg:DetailDescriptorSelector.DefaultValue>            
    
                <!-- A detail descriptor selected for master rows, whose Employees.Count value is equal to 0 -->
                <dxg:DetailDescriptorTrigger Binding="{Binding Path=Employees.Count}" Value="0">
                    <dxg:DataControlDetailDescriptor ItemsSourcePath="Customers">
                        <dxg:GridControl>
                            <!-- The detail GridControl settings -->
                        </dxg:GridControl>
                    </dxg:DataControlDetailDescriptor>
                </dxg:DetailDescriptorTrigger>
    
            </dxg:DetailDescriptorSelector>
        </dxg:GridControl.DetailDescriptor>
        <!-- The master GridControl settings -->
    </dxg:GridControl>
    

You can assign any detail descriptor to the triggers as a default value: DataControlDetailDescriptor, ContentDetailDescriptor, TabViewDetailDescriptor, and DetailDescriptorSelector.

See Also