A new issue !!

I have a checkbox column in the datagridview and also a column named "partqty" which displays the quantity of materails available.. I would want that when the user checks on the checkbox, the quantities of checked rows should be added and displayed in the textbox..

I tired something like this.. But it displays 0(zero) in the textbox.. Please help..

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        'For Each _rw As DataGridViewRow In dataGridView1.Rows
        '    If _rw.Cells(0).Value = True Then

        Dim totalSum As Integer

        For i As Integer = 0 To HemDatabase1DataSet5.Tables(0).Rows.Count - 1
            totalSum += HemDatabase1DataSet5.Tables(0).Rows(i).Item("partqty")
        Next

        textBox5.Text = totalSum.ToString()
        '    End If
        'Next
    End Sub

Hey !! This is something i could think upon trying !! however, there is no error during compile time, but there is an error at runtime, which says :
Operator '+' is not defined for type 'DBNull' and type 'Boolean'

Here is the code i tried :

For Each _rw As DataGridViewRow In dataGridView1.Rows
            If _rw.Cells(0).Value = True Then

                Dim totalSum As Integer

                For i As Integer = 0 To dataGridView1.Rows.Count - 1
                    totalSum += dataGridView1.Rows(i).Cells(5).Value
                Next

                textBox5.Text = totalSum.ToString()
            End If
        Next

It gives error on this line :

totalSum += dataGridView1.Rows(i).Cells(5).Value
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.