[RESOLVED] [2008] CheckBox Loop for Uncheck then Check
I have a little problem that nearly drives me xx! I've five Checkboxes and when I check the fifth I want the others to be unchecked and number five stay checked.
In runtime I got stuck with owerflow when it lies in "CheckBox5_CheckedChanged" Method and in other it wont just work guess it pretty simple right?
Code:
Private Sub CheckBox5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox5.Click
Dim Check As Control
If CheckBox5.Checked = True Then
CheckBox5.Checked = False
Exit Sub
Else
For Each Check In Me.GroupBox1.Controls
If TypeOf Check Is CheckBox Then
CType(Check, CheckBox).Checked = False
End If
Next
CheckBox5.Checked = True
End If
End Sub
Re: [2008] CheckBox Loop for Uncheck then Check
vb.net Code:
If not CheckBox5.Checked Then
For Each Check In Me.GroupBox1.Controls
If TypeOf Check Is CheckBox and check.name <> "CheckBox5" Then
CType(Check, CheckBox).Checked = False
End If
Next
End If
Re: [2008] CheckBox Loop for Uncheck then Check
Why do you need a loop? You know exactly what you want to do:
vb.net Code:
If Me.CheckBox5.Checked Then
Me.CheckBox1.Checked = False
Me.CheckBox2.Checked = False
Me.CheckBox3.Checked = False
Me.CheckBox4.Checked = False
End If
Re: [2008] CheckBox Loop for Uncheck then Check
Nice Paul that worked great thanks - much better syntax never would figuered that one out, I was stucked with my pretty If-code =)
To answear jmcilhinney I say that's not programming, and about my program there will be more checkboxes and maybe I do a Sub out of it.
Re: [2008] CheckBox Loop for Uncheck then Check
Quote:
Originally Posted by VBNetUser84
To answear jmcilhinney I say that's not programming
Hmmm... I could have sworn it was. Oh well. I guess I'll keep that in mind for the future.