Skip to main content
A newer version of this page is available. .

Iterate Through Rows

  • 2 minutes to read

Row traversing means accessing rows one by one. This can be useful, for example, when you need to locate a particular data row. This topic provides information on processing data rows. For information on how to process group rows, see Processing Group Rows.

Traversing Data Rows (Cards in Card Views)

Data rows are identified by their handles or visible indices. The total number of visible rows (group and data) is returned by the DataControlBase.VisibleRowCount property. If a View is grouped, some data rows can be hidden within collapsed group rows. In this instance, data rows contained within collapsed group rows are hidden, and not taken into account.

To traverse through all data rows including hidden rows, you should obtain their handles. Once you have determined the handles of all data rows, you only need a counter whose value is changed from 0 to the obtained number. The sample code below shows how to obtain the handles of data rows when a View is grouped.

Example: How to Collect the Handles of All Data Rows within a View (Including Rows in Collapsed Groups)

This example shows how to obtain the handles of all data rows (including rows in collapsed groups) contained within a View, except rows that are filtered out.

private List<int> GetDataRowHandles() {
    List<int> rowHandles = new List<int>();
    for (int i = 0; i < grid.VisibleRowCount; i++) {
        int rowHandle = grid.GetRowHandleByVisibleIndex(i);
        if (grid.IsGroupRowHandle(rowHandle)) {
            if (!grid.IsGroupRowExpanded(rowHandle)) {
                rowHandles.AddRange(GetDataRowHandlesInGroup(rowHandle));
            }
        }
        else
            rowHandles.Add(rowHandle);
    }
    return rowHandles;
}
private List<int> GetDataRowHandlesInGroup(int groupRowHandle) {
    List<int> rowHandles = new List<int>();
    for (int i = 0; i < grid.GetChildRowCount(groupRowHandle); i++) {
        int rowHandle = grid.GetChildRowHandle(groupRowHandle, i);
        if (grid.IsGroupRowHandle(rowHandle)) {
            rowHandles.AddRange(GetDataRowHandlesInGroup(rowHandle));
        }
        else
            rowHandles.Add(rowHandle);
    }
    return rowHandles;
}