Results 1 to 13 of 13

Thread: [RESOLVED] looping issue

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2011
    Posts
    72

    Resolved [RESOLVED] looping issue

    Hi,

    I'm trying to loop through a column of checkboxes to see how many checked values there are in that column. The user has to have 2; no more, no less than 2, otherwise an error should show up.

    Code:
     Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            Dim count As Integer = 0
            Dim x As Integer = 0
            For x = 1 To DataGridView1.RowCount - 1
                If CBool(DataGridView1.Rows(x).Cells(7).Value) Then
                    count = count + 1
                End If
            Next
            If count = 2 Then
                Me.Close()
            Else
                MsgBox("Error.")
                e.Cancel = True
            End If
    End Sub
    The error message still occurs when I have only 2 chosen in that column. I even tried this code:

    Code:
    If CBool(DataGridView1.Rows(x).Cells(7).Value = Checkstate.checked) Then
    Last edited by c3p0; Sep 1st, 2011 at 09:26 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width