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

Iterating Rows

You can iterate through grid rows using the Rows collection of GridViewRowInfo objects. The example below selects the last row, then iterates looking for selected rows. When the selected row is found, the GridViewRowInfo.EnsureVisible() method scrolls the row into the view:

GridViewRowInfo lastRow1 = radGridView1.Rows[radGridView1.Rows.Count - 1];
lastRow1.IsSelected = true;
foreach (GridViewRowInfo rowInfo in radGridView1.Rows)
{
    if (rowInfo.IsSelected)
    {
        rowInfo.EnsureVisible();
    }
}

Finding a grid row by a value of one of its cells

You could search for a specific value in RadGridView by iterating through the rows and compare cells value. In the example below, you search for searchedStr in MyColumnName column:

string searchedStr = "Picture 2";
for (int r = 0; r < radGridView1.RowCount; r++)
{
    if (radGridView1.Rows[r].Cells["Picture Name"].Value.ToString().ToUpper().Equals(searchedStr.ToUpper()))
    {
        MessageBox.Show("Found a match");
        //do something 
    }
}

Iterating all rows in a self-reference hierarchy

When you have a hierarchical grid with many templates you can use a recursive method to iterate trough all rows:

public void IterateAllRows(IEnumerable<GridViewRowInfo> rowsCollection)
{
    foreach (GridViewDataRowInfo row in rowsCollection)
    {
        Debug.WriteLine(row.Cells[0].Value);//This rows is used for demonstration only!
        if (row.HasChildRows())
        {
            IterateAllRows(row.ChildRows);
        }
    }
}

Iterating hierarchical grid.

You can iterate through grid rows using the Rows collection of RadGridView objects. The example below cycles through the rows of the grid, modifies the values for certain cells in the different hierarchy levels and counts the rows and cells in the whole RadGridView.

private void radButton1_Click(object sender, EventArgs e)
{
    int count = 0;
    int i = 0;
    foreach (GridViewDataRowInfo dataRow in this.GetAllRows(this.radGridView1.MasterTemplate))
    {
        count++;
        foreach (GridViewCellInfo cell in dataRow.Cells)
        {
            if (cell.ColumnInfo.Name == "CompanyName" || cell.ColumnInfo.Name == "ShipCountry")
            {
                cell.Value = "TEST";
            }
            if (cell.ColumnInfo.Name == "UnitPrice")
            {
                cell.Value = 1.11111;
            }
            i++;
        }
    }
}
public List<GridViewRowInfo> GetAllRows(GridViewTemplate template)
{
    List<GridViewRowInfo> allRows = new List<GridViewRowInfo>();
    allRows.AddRange(template.Rows);
    foreach (GridViewTemplate childTemplate in template.Templates)
    {
        List<GridViewRowInfo> childRows = this.GetAllRows(childTemplate);
        allRows.AddRange(childRows);
    }
    return allRows;
}