Looping through a DataGrid

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
 
E

EdanStarfire

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top