mohamed soliman
mohamed soliman

Reputation: 21

datagridveiw count value when checked checkbox in textbox and when unchecked still count

I have datagridview like this:

enter image description here

when I check the checkbox in first column it count the value of last column in textbox and using this code :

Dim result As String
    For n = 0 To DGV1.Rows.Count - 1
        If DGV1.Rows(n).Cells(0).Value = True Then
            result = DGV1.Rows(n).Cells(2).Value
            '
        End If
    Next
    Textbox1.Text = Val(Textbox1.Text) + Val(result)

but when I uncheck the checkbox and check it again it's still count but I want the textbox count when I checked the checkbox and Minus from the count when I unchecked the checkbox thank you all

Upvotes: 0

Views: 703

Answers (1)

Slai
Slai

Reputation: 22876

Private Sub DGV1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DGV1.CellValueChanged
    if e.ColumnIndex = 0 AndAlso e.RowIndex >= 0 Then
        Dim query = From r In DGV1.Rows.Cast(Of DataGridViewRow)
                    Where True.Equals(r.Cells(0).Value)
                    Select Val(r.Cells(2).Value)
        Textbox1.Text = q.Sum
    End If
End Sub

Upvotes: 1

Related Questions