Total up a datagrid to a separate textbox
Can somebody please help me
i have a datagrid with with the columns Length, Height and Total, length*height = Total
i want to summarize that to a textbox outside the grid. I'm using visual basic 2005 language
thanks
Steve
mike APosted Feb 22, 2010, 2:10 PM
lets say we have a datgridview called "DGV1" which has three columns and three rows. The first cell (upper left hand cell) would be DGV.item(0,0) where (0,0) are:
(columnIndex as Int, rowindex as Int).
to sum the rows and/or colums you would simply need to create a loop or a couple of loops with counting variables that would cycle through the rows/columns adding the value of each cell to the running total example:
the following example will sum a row
'subtract 1 from rowcount because first cell index 0, so last cell will have index 2 (0, 1, 2)
to sum a column instead of a row, you would change runTotal in the loop to be:
to sum all cells in the table: