The Telerik website has a tutorial for multi-level gridview at this link: https://docs.telerik.com/devtools/winforms/controls/gridview/hierarchical-grid/binding-to-hierarchical-data-programmatically
And there is a tutorial for Load-On-Demand at this link: https://docs.telerik.com/devtools/winforms/controls/gridview/hierarchical-grid/load-on-demand-hierarchy
But there is none that applies both together. My goal is a 3-level gridview where each level loads when needed.
What I've managed to implement so far is a gridview with two levels using lazy loading. However, there is a need for one more level:
private GridViewTemplate CreateChildTemplate()
{
GridViewTemplate template = new GridViewTemplate();
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
var properties = typeof(FirstChildClass).GetProperties();
foreach (var property in properties)
{
template.Columns.Add(new GridViewTextBoxColumn
{
Name = property.Name,
HeaderText = property.Name
});
}
return template;
}
private async void ExampleRadGridView_RowSourceNeeded(object sender,
Telerik.WinControls.UI.GridViewRowSourceNeededEventArgs e)
{
firstChildClassList = new BindingList<FirstChildClass>(await
_controller.GetFirstChildClass(ParentID);
var columns = e.Template.Columns;
GridViewRowInfo _newRowObj = e.Template.Rows.NewRow();
foreach (var element in orderDetailList)
{
foreach (var column in columns)
{
string columnName = column.Name;
var property = typeof(FirstChildClass).GetProperty(columnName);
if (property != null)
_newRowObj.Cells[columnName].Value = property.GetValue(element);
}
e.SourceCollection.Add(_newRowObj);
}
}
private async void FillGridView()
{
radGridView.Templates.Clear();
parentList = new BindingList<ParentClass>(await _controller.GetParent(ID);
radGridView.DataSource = orderList;
var _childTemplate = CreateChildTemplate();
radGridView.Templates.Add(_childTemplate);
_childTemplate.HierarchyDataProvider = new GridViewEventDataProvider(_childTemplate);
radGridView.RowSourceNeeded -= ExampleRadGridView_RowSourceNeeded;
radGridView.RowSourceNeeded += ExampleRadGridView_RowSourceNeeded;
}
In order to construct a n-level hierarchy in the RadGridView, you should add a GridViewTemplate for each level. Afterwards, it is necessary to initialize the HierarchyDataProvider for the certain template. Thus, using the RadGridView.RowSourceNeeded event, you can load on demand the hierarchical data, considering the ParentRow.HierarchyLevel. Please refer to the following code snippet: