troubleshooting Question

VB.NET 2003 - FORCING USER TO CLICK A PRE-DETERMINED NUMBER OF CHECKBOXES ONLY

Avatar of pythonV
pythonV asked on
Visual Basic.NET
4 Comments1 Solution223 ViewsLast Modified:
Hi,

I dropped a Groupbox onto my form, and dropped 5 Checkboxes in it.

The idea is to put code in the Groupbox which forces the user to choose 1 or 2 checkboxes only from a possible 5. I want the code to disallow the user from proceeding if he does not check at least one box or checks 3 or more. The Groupbox also has a label which will display the message "Choose 1 or 2 Boxes" until these conditions are met by the user.

in other words, the user won't be allowed to click the Button (which performs another unrelated operation) but will be stuck in the Groupbox until he meets conditions.

The following is the Code View:

Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
        Dim checkMax As Int16

        If CheckBox1.Checked = True Then
            checkMax = (checkMax + 1)
        End If
        If CheckBox2.Checked = True Then
            checkMax = (checkMax + 1)
        End If
        If CheckBox3.Checked = True Then
            checkMax = (checkMax + 1)
        End If
        If CheckBox4.Checked = True Then
            checkMax = (checkMax + 1)
        End If
        If CheckBox5.Checked = True Then
            checkMax = (checkMax + 1)
        End If

        If checkMax = 0 Or checkMax > 2 Then
            Label1.Text = "You can only check 1 or 2 boxes"
        Else : Label1.Text = ""
        End If

    End Sub



Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros