Home All Groups Group Topic Archive Search About

Sum of a DataGridView column

Author
24 Oct 2006 3:14 AM
Tony A.
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

Author
24 Oct 2006 6:22 AM
Norman Chong
Tony A. schrieb:

> 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

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
Author
25 Oct 2006 3:26 PM
Tony A.
Thanks Norman.
--
Tony


Show quoteHide quote
"Norman Chong" wrote:

>
> Tony A. schrieb:
>
> > 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
>
> 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
>
>