Well, in my attempt to complete this application more questions have arisen.
On my form I have placed three checkboxes. Is there a way to make only two of these three checkboxes checked at a time?
-Thank you.
Question Involving CheckBoxes
- WaywornMmmmm
- Posts: 1341
- Joined: Sat Nov 05, 2005 5:17 am
- Location: U.S.A
- StalkingGrunt911
- Posts: 3618
- Joined: Wed May 24, 2006 12:30 pm
- Location: Florida!
- Contact:
So you mean if you check one the other checks too? If so just double click on the one you want to check to make the other checkbox checked off to.
The code if Visual Basic would be something like
or if it's C# something like
I believe that is it, I haven't opened up VB or C# in a while but I'm pretty sure that's how to do it.
The code if Visual Basic would be something like
Code: Select all
//CheckBox1 & 2 just being as the name for whatever checkbox you plan to use
Public Sub CheckBox1_Checked(ByVal sender As Object, ByVal e As EventArgs) As Handles.CheckBox1_Checked
If CheckBox1.Checked = True Then
Me.CheckBox2.Checked = True
End If
End Function
Code: Select all
private sub checkBox1_Checked (object sender, EventArgs e)
{
if(checkBox1.Checked == true)
{
this.checkBox2.Checked = true;
}
}
It is, but I think he meant that if two were checked, you could not check a third. If that is the case,
That method is linked to all the checkbox's CheckChanged event, but if you do need to separate it out for w/e reason then you can easily put it in it's own function and call it as needed.
Code: Select all
private void checkBox1_2_3_CheckedChanged(object sender, EventArgs e)
{
CheckBox box = (sender as CheckBox);
if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
box.Checked = false;
}
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
Halo 3 Research Thread - Contribute to the research into Halo 3.
Haha I was thinking more complicated than I needed to be, I was thinking of a way to make it so when you checked a check box, and there were 3 being checked, the first one that you had checked would become unchecked and you'd check the one that you just clicked.
Also prey what's with the (sender as CheckBox)? is that the same as casting it, or does it have different performance.
Also prey what's with the (sender as CheckBox)? is that the same as casting it, or does it have different performance.
It is casting, just another way of doing it. This will also only work for reference types though, so I normally use it for such things only because of its readability; it flows better than doing it the other way, and thus goes further towards maintaining good code that is easily understandable, something you should always strive to do with any project.OwnZ joO wrote:Also prey what's with the (sender as CheckBox)? is that the same as casting it, or does it have different performance.
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
Halo 3 Research Thread - Contribute to the research into Halo 3.