Sum of a DataGridView column

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

On a Windows form I have a DataGridView. I woulkd like to display the sum of
some of the columns in the DataGridView, but I can't firnd any information on
how to do this.

Any suggestion on how I can best do this? Thanks in advance.
 
Tony said:
On a Windows form I have a DataGridView. I woulkd like to display the sum of
some of the columns in the DataGridView, but I can't firnd any information on
how to do this.

Any suggestion on how I can best do this? Thanks in advance.

I checked the methods that the Grid, Rows, Columns, etc offers but
haven't found anything which can do this... Seems that you have to
write your own method :-(
Won't be too hard to do this: Just get the columns/cells and do the job
within a loop:

Dim mySum as Integer = 0
Dim currentRow as DataGridViewRow
For Each currentRow In dgvMyGrid.rows
mySum += CInt(currentRow.Cells( <CellIndex> ).Value)
Next
 
Thanks Norman.
--
Tony


Norman Chong said:
I checked the methods that the Grid, Rows, Columns, etc offers but
haven't found anything which can do this... Seems that you have to
write your own method :-(
Won't be too hard to do this: Just get the columns/cells and do the job
within a loop:

Dim mySum as Integer = 0
Dim currentRow as DataGridViewRow
For Each currentRow In dgvMyGrid.rows
mySum += CInt(currentRow.Cells( <CellIndex> ).Value)
Next
 
Back
Top