Looping through a DataGrid

  • Thread starter Thread starter Shawn
  • Start date Start date
S

Shawn

Hi.
I have a DataGrid that is displaying records from my DB. The fifth column
in my DataGrid contains a number. I need to calculate the number in that
column for all the rows, but I can't figure out how to do it. Something like
this:

For each row in Datagrid
mycounter = mycounter + row(5)
Next

Can someone show me how to do this?

Thanks,
Shawn
 
you could use the CellFormatting event...

private void Datagrid_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
if(Datagrid.Columns[5].Name == "Counter") //Or whatever you called
//that column...
{
mycounter += (Int32) e.Value; // Whatever type it should
//be double, decimal, int
//etc...
}
}
 
Back
Top