You use the row index and column index as indexers on the DataGrid object.
private void IterateOverDataTable()
{
CurrencyManager cm =
(CurrencyManager) BindingContext[ dataGrid1.DataSource ];
int rowCount = cm.Count;
// assumes data source is a DataTable
int colCount = ( (DataTable) dataGrid1.DataSource ).Columns.Count;
for ( int row = 0; row < rowCount; ++row )
for ( int col = 0; col < colCount; ++col )
{
object cellValue = dataGrid1[ row, col ];
// process cellValue here...
}
}
Contributed from George Shepherd's Windows Forms FAQ