Self-Referencing GridView
Except displaying hierarchical data and applying some custom criteria about when the subset of data is to be displayed, RadGridView allows you to define a relation that points back to the same collection. In the cases when the hierarchical data is build from one type of items, you can use a self referencing RadGridView to display the data.
This tutorial demonstrates how you can build a self-referencing hierarchy.
Example 1 demonstrates an ordinary RadGridView declaration, populated with some data:
Example 1: RadGridView declaration
Example 2: Creating the ViewModel
The ChildTableDefinitions property of the RadGridView allows you to display objects which are related to objects of the same type, thus modelling a tree structure. Example 3 demonstrates how this can be achieved with the Employee class defined in Example 2.
Example 3: Setting the ChildTableDefinitions
ParentFieldDescriptorName - specifies the name of the property of the object in the parent RadGridView, that is on one side of the relation.
ChildFieldDescriptorName - specifies the name of the property of the object in the child RadGridView, that is on the other side of the relation.
In the child RadGridView the entries of the RadGridView's source are displayed, which values of the property, specified as the ChildFieldDescriptorName, are equal to the value of the property, specified as the ParentFieldDescriptorName.
Figure 1 demonstrates the result from Example 3:
Figure 1: Self-referencing RadGridView
You can specify more than one FiledDescriptorNamePair. For example, define a relation that specifies that the child objects should have the same title as the parent object.
Example 4: Specifying two FiledDescriptorNamePair
Figure 2: Custom relation
In order to hide the GridViewToggleButton that expands the hierarchy for items that do not have subitems, you can introduce a boolean property in the Employee class and use the IsExpandableBinding property of the RadGridView.
In order to learn how to modify the child RadGridViews, check out the How-to: Set properties to the child gridview article.