Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
VB.NET
Public Class Form16
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        Dim check As Boolean
        For i As Integer = 0 To DataGridView3.Rows.Count
            check = DataGridView3.Rows(i).Cells(1).Value
            If check Then
                Exit For
            End If
        Next
        If Not check Then
            MessageBox.Show("You didn't check any checkbox")
        End If
    End Sub
End Class


What I have tried:

Datagridview3 = 2 columns: Name, Work
I tried to change DataGridView3.Rows(i).Cells(1).Value TO DataGridView3.Rows(i).Cells("Work").Value BUT I see another problem.
Can you help me ? Thanks !
Posted
Updated 5-Apr-16 1:01am
Comments
John C Rayan 5-Apr-16 6:57am    
Debug and see this line DataGridView3.Rows(i).Cells(1).Value to see the indexes are valid for all rows.
ionMEMBER 5-Apr-16 7:04am    
If I change DefaultValue from 'DBNull' to 0 (false) then problem is:
Conversion from type 'DBNull' to type 'Boolean' is not valid.

1 solution

Your loop iterates up to (and including) DataGridView3.Rows.Count. Change it to one less:
VB
For i As Integer = 0 To DataGridView3.Rows.Count - 1
 
Share this answer
 
Comments
phil.o 5-Apr-16 7:02am    
Dammit you beat me :)
I delete my solution which is redundant.

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