Click here to Skip to main content
16,021,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all!

I'm trying to count the number of the checked checkboxes in the datagridview, but the counter return value is 0.
Can anyone give me a clue why that is so?

VB
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

        Dim pcount As Integer = 0
        For Each row As DataGridViewRow In DataGridView1.Rows
            If row.Cells(0).Value = True Then
                pcount += 1
            End If
        Next
        Label2.Text = pcount
    End Sub



Thanks!
Posted
Updated 5-Dec-10 2:59am
v2
Comments
Manfred Rudolf Bihy 5-Dec-10 9:01am    
Minor changes and code tag correction.

1 solution

You must be re-binding the grid to dataset again in form load, before the event is executed! Use DEBUGGER and see if that's the case.
 
Share this answer
 
Comments
edriso 5-Dec-10 15:24pm    
done that, but when i uncheck the box sometimes it return a wrong row counted
ex ( if i cheched 1 box it counts 3 )

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900