New to Telerik UI for WinForms? Start a free 30-day trial
Iterating the child rows collection of a chosen parent row in hierarchy RadGridView
Updated over 6 months ago
In order to iterate all child rows in RadGridView, you need to change the ActiveView of each hierarchy row to each of the available Views. This is needed as the grid will create the child rows for the sibling views (tabs in the detail cell) only after they are requested - when the tab is clicked.
C#
void IterateRows()
{
foreach (GridViewRowInfo row in radGridView1.Rows)
{
Console.WriteLine(row.Cells[1].Value);
GridViewHierarchyRowInfo hierarchyRow = row as GridViewHierarchyRowInfo;
if (hierarchyRow != null)
{
IterateChildRows(hierarchyRow);
}
}
}
private void IterateChildRows(GridViewHierarchyRowInfo rowInfo)
{
GridViewInfo currentView = rowInfo.ActiveView;
foreach (GridViewInfo view in rowInfo.Views)
{
rowInfo.ActiveView = view;
foreach (GridViewRowInfo row in rowInfo.ChildRows)
{
Console.WriteLine(row.Cells[2].Value);
}
}
rowInfo.ActiveView = currentView;
}