Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-06-2009
Member
 
Join Date: Apr 2009
Posts: 79
Calculating sum of column in datagrid

I am looking for program which include a datagrid component on form. The control on the form will add the value like price, year, model no from given column and display total of the grid in the textbox which is at the top of the form.
Reply With Quote
  #2  
Old 09-06-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Calculating sum of column in datagrid

Code:
  Dim sum As Decimal = 0
        For Each row As DataGridViewRow In DataGridView1.Rows
            row.Cells(37).Value = row.Cells(36).Value - row.Cells(6).Value * 113 / row.Cells(4).Value
            sum += row.Cells(37).Value   
        Next
        App.txtvalue.Text = sum
Reply With Quote
  #3  
Old 09-06-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Calculating sum of column in datagrid

Code:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles App.Load
        Dim tb As New DataTable
        tb.Columns.Add("income", GetType(System.Int32))
        tb.Columns.Add("income1", GetType(System.Int32))
        tb.Columns.Add("sum", GetType(System.Int32))
        tb.Rows.Add(500, 200)
        tb.Rows.Add(0, 100)
        tb.Rows.Add(200, 100)
        Me.DataGridView1.DataSource = tb
    End Sub
    Private Sub DataGridView1_Columncalculated(ByVal sender As Object, ByVal i As System.Windows.Forms.DataGridViewcolumn) Handles DataGridView1.Columncalculated

        Dim sum As BB = 0
        For Each n As DataGridViewRow In Me.DataGridView1.Rows
            sum = sum + r.Cells(0).Value - r.Cells(1).Value
            r.Cells(2).Value = sum
        Next
    End Sub
End Class
Reply With Quote
  #4  
Old 09-06-2009
Member
 
Join Date: Jan 2009
Posts: 199
Re: Calculating sum of column in datagrid

Code:
Dim CalSum As Double
Dim CalValue As Double
Dim DRow As Long

With MSFlexGrid1
  ' loop through all data rows
  For DRow = .FixedRows To .Rows - 1
    ' get the value for the current row
    CalValue = Val(.TextMatrix(lRow, 3))
    ' add it to our total
    CalSum = CalSum + CalValue
  Next DRow
  ' Add a new row
  .Rows = .Rows + 1
  ' Put the total in the new row
  .TextMatrix(.Rows - 1, 3) = CalSum
End With
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Calculating sum of column in datagrid"
Thread Thread Starter Forum Replies Last Post
Find The Value of one column in another column Charth Windows Software 3 23-02-2011 03:01 AM
How to highlight identical cell value of one column in another column? D_chapple Windows Software 3 09-12-2009 01:11 PM
How to set and hide the Datagrid column in Compact Framework Balgovind Windows Software 2 09-06-2009 08:11 PM
mysql update column with another column Gunter Software Development 3 23-05-2009 09:44 AM
Adding a new column in datagrid at runtime? Leena Software Development 3 13-02-2009 07:00 PM


All times are GMT +5.5. The time now is 01:21 PM.