You could associate an Action with each CheckBox, and Invoke the Actions associated with the checked checkboxes. How you do this association is up to you, you could have a Dictionary(Of CheckBox, Action), you could use the Tag property, etc.
Example:
(Not very sure about syntax, it's been a while since I fired up VB)Code:Private checkboxes As Dictionary(Of CheckBox, Action) Private Sub SetupCheckboxes() checkboxes = New Dictionary(Of CheckBox, Action)() checkboxes.Add(CheckBox1, New Action(AddressOf Method1)) checkboxes.Add(CheckBox2, New Action(AddressOf Method2)) checkboxes.Add(CheckBox3, New Action(AddressOf Method3)) checkboxes.Add(CheckBox4, New Action(AddressOf Method4)) End Sub Private Sub ExecuteMethods() 'Call on button click or whatever For Each kvp As KeyValuePair(Of CheckBox, Action) In checkboxes Dim checkbox = kvp.Key Dim action = kvp.Value If checkbox.Checked Then action.Invoke() Next End Sub
That's how you could do it, whether it's useful? I dunno... There are probably better ways to do what you want.




Reply With Quote