At runtime, if the data source for the grid is a System.Data.DataSet type and there are relations defined in
it, the hierarchy can be created automatically. Set the AutoGenerateHierarchy property true
to get this behavior. In the example below, the Northwind dataset has Categories and Products joined by CategoryID.
The run-time code fills the categories and products data tables, sets the AutoGenerateHierarchy to
true, assigns the data set containing both tables to the grid DataSource and
the DataMember is the name of the parent table. The last three lines of code below can be configured at design time.
Copy[C#] Generating Hierarchy From a DataSet
private void BindingToHierarchicalGridAutomatically_Load(object sender, EventArgs e)
{
this.productsTableAdapter.Fill(this.nwindDataSet.Products);
this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories);
radGridView1.AutoGenerateHierarchy = true;
radGridView1.DataSource = this.nwindDataSet;
radGridView1.DataMember = "Categories";
}
Copy[VB.NET] Generating Hierarchy From a DataSet
Private Sub BindingToHierarchicalGridAutomatically_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ProductsTableAdapter.Fill(Me.NwindDataSet.Products)
Me.CategoriesTableAdapter.Fill(Me.NwindDataSet.Categories)
RadGridView1.AutoGenerateHierarchy = True
RadGridView1.DataSource = Me.NwindDataSet
RadGridView1.DataMember = "Categories"
End Sub