Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Calculating values in a datagrid

Calculating values in a datagrid

Scheduled Pinned Locked Moved Visual Basic
csharpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Psyfo
    wrote on last edited by
    #1

    Hi everyone Im using VB.Net 2003. I have a field in a datagrid "Total", how do i calculate the total:sigh: and Display it in a label

    S 1 Reply Last reply
    0
    • P Psyfo

      Hi everyone Im using VB.Net 2003. I have a field in a datagrid "Total", how do i calculate the total:sigh: and Display it in a label

      S Offline
      S Offline
      Scott Page
      wrote on last edited by
      #2

      I would suggest enumerating all rows of the datasource (datatable) and summing up each value from the target column. It would look something like this: (assuming there is a DataTable already created called DT

      Dim Total As Double = 0#
      For Each R As DataRow In DT.Rows
      Total += R(1) 'This line simply adds the value from Column 1 of the current row.
      Next
      Me.label1.Text = Total.ToString() 'Set the labels text property to display the total.

      If you have a strongly typed DataTable, you may have access to the Properies of each DataRow to use instead of getting the column data using the index of in the row. For example R.Price instead of R(1). Hope that does the trick. "Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem." ( President Ronald Reagan) -- modified at 21:50 Monday 28th August, 2006

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups