Sum of a DataGridView column

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony A.

    #1

    Sum of a DataGridView column

    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
  • Norman Chong

    #2
    Re: Sum of a DataGridView column


    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).Val ue)
    Next

    Comment

    • Tony A.

      #3
      Re: Sum of a DataGridView column

      Thanks Norman.
      --
      Tony


      "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).Val ue)
      Next
      >
      >

      Comment

      Working...