J
John Wright
I have a datagridview on my form that has two columns. Column 0 is a
checkbox, column 1 is a text field. When a user checks or unchecks the
checkbox, I need to get a count of all the checked items in the datagrid. I
tried to use cellclick, cellvaluechanged, CellMouseUp and I cannot get the
event to fire for the first click.
I am attaching the code to show what I am doing (I am just looping through
the table and counting all the items where cell(0) is true). What event
should I use to get the value. When I use cellclick is doesn't register the
checkbox as checked/unchecked so the count is off. Thanks.
Code:
Dim intPieceCount As Integer = 0
Dim i As Integer = dgEPNItems.Rows.Count - 1
For x As Integer = i To 0 Step -1
If x < 0 Then
Exit For
End If
Dim dr As DataGridViewRow
dr = dgEPNItems.Rows(x)
If dr.Cells(0).Value = True Then
intPieceCount += 1
End If
Next
txtQuantity.Text = CStr(intPieceCount)
John
checkbox, column 1 is a text field. When a user checks or unchecks the
checkbox, I need to get a count of all the checked items in the datagrid. I
tried to use cellclick, cellvaluechanged, CellMouseUp and I cannot get the
event to fire for the first click.
I am attaching the code to show what I am doing (I am just looping through
the table and counting all the items where cell(0) is true). What event
should I use to get the value. When I use cellclick is doesn't register the
checkbox as checked/unchecked so the count is off. Thanks.
Code:
Dim intPieceCount As Integer = 0
Dim i As Integer = dgEPNItems.Rows.Count - 1
For x As Integer = i To 0 Step -1
If x < 0 Then
Exit For
End If
Dim dr As DataGridViewRow
dr = dgEPNItems.Rows(x)
If dr.Cells(0).Value = True Then
intPieceCount += 1
End If
Next
txtQuantity.Text = CStr(intPieceCount)
John