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

try this ..................


Dim table As DataTable
table = Me.SilaaBackupDataSet.Tables("Unlisted")
Me.txttotal1.Text = table.Compute("sum(Total)", String.Empty)
Me.txtduty.Text = table.Compute("Sum(TotalofCDT)", String.Empty)

What is the type of cells(0)? Would it have a true/false as value ?
Have you tried to step through the program and determine what is wrong with your code?

I realized thats where i m going wrong.. 1st column is abt item names, it cannot be true or false.. :(
However, m still struggling to find a solution out !! :(

Thank You !! :)

Are you trying to add the values from "Selected" Rows? If so, try

For each r as DataGridViewRow in DataGRidView1.SelectedRows

                CurrentCellValue = r.Cells(1).Value
                If CurrentCellValue = "" Then CurrentCellValue = 0
             
                CumulativeSummer += Convert.ToInt32(CurrentCellValue)
                
            Next
This question has already been answered. Start a new discussion instead.