2 Replies - 958 Views - Last Post: 23 November 2011 - 10:58 PM Rate Topic: -----

#1 Ruchi22  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 23-September 11

datagridview add total

Posted 23 November 2011 - 03:28 AM

Hello..

I have a datagridview.. It is unbound to any database and has 2 columns..

1 is item name and other is amount/expense, incurred..

I want the total of expense incurred be displayed in the textbox on button click ie adding the numbers in amount column..

I tried something like this, but not working.. Please help !!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim iSselected As Boolean
        Dim CurrentCellValue As String
        Dim CumulativeSummer As Integer
        Dim i As Integer

        With Me.DataGridView1
            For i = 0 To .RowCount - 1
                iSselected = .Rows(i).Cells(0).Value
                CurrentCellValue = .Rows(i).Cells(1).Value
                If CurrentCellValue = "" Then CurrentCellValue = 0

                If iSselected = True Then
                    CumulativeSummer += Convert.ToInt32(CurrentCellValue)
                End If
            Next
        End With

        Me.TextBox2.Text = CumulativeSummer



Is This A Good Question/Topic? 0
  • +

Replies To: datagridview add total

#2 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1746
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: datagridview add total

Posted 23 November 2011 - 01:30 PM

Wait, you said you have two columns and the first one hold names:

Quote

1 is item name and other is amount/expense, incurred..

Then what is boolean doing to names?
 iSselected = .Rows(i).Cells(0).Value
what do you expect to get from the names assigned to boolean than error message?

If you just want to add all column values, then you dont need to bother about the name column.... just loop through all rows and add the value. So no need to if statement or iSselected unless you have another thing you want to do than just adding values.
Was This Post Helpful? 1
  • +
  • -

#3 Ruchi22  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 23-September 11

Re: datagridview add total

Posted 23 November 2011 - 10:58 PM

Ohk.. I thought i could use some variable to count number of rows..

But anyways, i just removed if clause and its working fine !!

Thank you.. :)

This post has been edited by Ruchi22: 24 November 2011 - 01:36 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1