Multiple Checkboxes, 1 Varible

Is it possible to have mutliple checkboxes (two or three) change the same variable, but when one of them is set to True, all change to True?
[140 byte] By [Raybritton] at [2007-12-28]
# 1

one way would be to place the checkboxes in 1 groupbox then on the checkedchanged event for each checkbox, if the current checkbox is checked then for each checkbox in the groupbox - set the current checkbox in the iteration loop to checked (true)

example...

private sub Checkbox1_CheckedChanged(byval sender as object, byval e as eventargs) handles Checkbox1.CheckedChanged

if Me.Checkbox1.Checked = true then

for each currentCheckbox as CheckBox in Me.groupBox1.Controls

currentCheckbox.Checked = true

next

end if

end sub

this is just 1 example, which has no error checking to see if the current control is infact a checkbox or not.

is this what you maybe after?

ahmedilyas at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Sorry, I should have explained more, the checkboxes will be on different tabs, I gettings a list of programs, and to make it easier for users I will have the program repeated for example: Microsoft Word would come under Microsoft Word, Word and Office Word.
Raybritton at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

private sub Checkbox1_CheckedChanged(byval sender as object, byval e as eventargs) handles Checkbox1.CheckedChanged, Checkbox2.CheckedChanged, Checkbox3.ChecledChanged

if Sender=CheckBox1 then

Checkbox2.Checked=CheckBox1.Checked

Checkbox3.Checked=Checkbox1.checked

elseif Sender=CheckBox2 then

Checkbox1.Checked=CheckBox1.Checked

Checkbox3.Checked=Checkbox1.checked

elseif Sender=Checkbox3 then

Checkbox1.Checked=CheckBox1.Checked

Checkbox2.Checked=Checkbox1.checked

end if

end sub

robinjam at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

You also can create a form-level property like that:

Private Property MyGroupChecked() As Boolean
Get
Return
CheckBox1.Checked

End Get
Set
(ByVal Value As Boolean)
CheckBox1.Checked = Value
CheckBox2.Checked = Value
' and so on ...
End Set
End Property

And then, write this event handler:

Private Sub MyGroupHandler(ByVal sender As Object, ByVal e As EventArgs) Handles _
CheckBox1.CheckedChanged, CheckBox2.CheckedChanged ' and so on ...
MyGroupChecked = CType(sender, CheckBox).Checked
End Sub

This is little more flexible and allows you to change the state of checkboxes programmatically in one line of code:

MyGroupChecked = True

Vano at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
Thanks for the help
Raybritton at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...