Version

We recommend that you use the xamDataGrid control instead of the xamGrid control. The xamGrid is being planned for retirement over the next few years and will not receive any new features. We will continue to provide support and critical bug fixes for the xamGrid during this time. For help or questions on migrating your codebase to the xamDataGrid, please contact support.

Defining a Self Related Hierarchical Structure

The xamGrid control also allows you to use column layouts to define self-related hierarchical data structures. A typical example of self-related data is an employee hierarchy, where managers have employees, who themselves are also managers and have employees.

The following example shows you how display a self-related structure by binding xamGrid to the Employees collection referred to at the beginning of the article. All you need to do is create a ColumnLayout object that uses the TargetTypeName to match the Employees collection exposed by the Employee data source.

In XAML:

<ig:XamGrid x:Name="xamGrid1" AutoGenerateColumns="False">
    <ig:XamGrid.ColumnLayouts>
        <ig:ColumnLayout Key="DirectReports" TargetTypeName="Employee">
            <ig:ColumnLayout.Columns>
                <ig:TextColumn Key="Id" />
                <ig:TextColumn Key="Name" />
                <ig:TextColumn Key="JobTitle" />
            </ig:ColumnLayout.Columns>
        </ig:ColumnLayout>
    </ig:XamGrid.ColumnLayouts>
</ig:XamGrid>
sl xamGrid Define Column Layout 08.png

You can also control how many levels deep the xamGrid will traverse the self-related data structure by setting the control’s MaxDepth property.

In XAML:

<ig:XamGrid x:Name="xamGrid1" AutoGenerateColumns="False" MaxDepth="1">
Note
Note:

The MaxDepth property is a zero-based value, where zero is the root column layout. So in this case, the max depth is one level past the root layout: MaxDepth = 1.