New to Telerik UI for WinForms? Download free 30-day trial

Iterating the child rows collection of a chosen parent row in hierarchy RadGridView

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.

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;
}

Private Sub IterateRows()
    For Each row As GridViewRowInfo In radGridView1.Rows
        Console.WriteLine(row.Cells(1).Value)
        Dim hierarchyRow As GridViewHierarchyRowInfo = TryCast(row, GridViewHierarchyRowInfo)
        If hierarchyRow IsNot Nothing Then
            IterateChildRows(hierarchyRow)
        End If
    Next
End Sub
Private Sub IterateChildRows(rowInfo As GridViewHierarchyRowInfo)
    Dim currentView As GridViewInfo = rowInfo.ActiveView
    For Each view As GridViewInfo In rowInfo.Views
        rowInfo.ActiveView = view
        For Each row As GridViewRowInfo In rowInfo.ChildRows
            Console.WriteLine(row.Cells(2).Value)
        Next
    Next
    rowInfo.ActiveView = currentView
End Sub

See Also

In this article