E
eBob.com
I've used AddHandler for a UNIQUE control added to a panel and it
seemed to work. But now I want to add a bunch of controls to a panel
and use only one event handler subroutine. And I am completely lost.
Below is the essence of the code adding checkbox controls to a panel.
(Corresponding to each checkbox is another checkbox and a label.)
Do I have to use AddHandler in the loop? Or is there someway outside
of a loop to say that a particular sub is the event handler for all
controls in an array of controls? The syntax of my AddHandler is
wrong but I cannot figure out how to fix it.
I have to be able to figure out in the event handler code WHICH
checkbox was checked. So I'd like to get the index value of the
control passed as an argument to the event handler sub. But that's
another thing which I can't figure out.
When I pnlAttrs.Controls.Clear() will that undo the AddHandler or must
I use RemoveEventHandler? And what would the syntax of the
RemoveEventHandler be?
Here's the code ...
For i As Integer = 0 To x
chkbxSel(i) = New CheckBox
pnlAttrs.Controls.Add(chkbxSel(i))
AddHandler chkbxSel(i).Click, AddressOf chkbxSelI_Click '< ??
Next
Private Sub chkbxSelI_Click(ByVal i As Integer)
MsgBox("bingo for number " & i.ToString)
End Sub
Any and all help will be appreciated.
Thanks, Bob
seemed to work. But now I want to add a bunch of controls to a panel
and use only one event handler subroutine. And I am completely lost.
Below is the essence of the code adding checkbox controls to a panel.
(Corresponding to each checkbox is another checkbox and a label.)
Do I have to use AddHandler in the loop? Or is there someway outside
of a loop to say that a particular sub is the event handler for all
controls in an array of controls? The syntax of my AddHandler is
wrong but I cannot figure out how to fix it.
I have to be able to figure out in the event handler code WHICH
checkbox was checked. So I'd like to get the index value of the
control passed as an argument to the event handler sub. But that's
another thing which I can't figure out.
When I pnlAttrs.Controls.Clear() will that undo the AddHandler or must
I use RemoveEventHandler? And what would the syntax of the
RemoveEventHandler be?
Here's the code ...
For i As Integer = 0 To x
chkbxSel(i) = New CheckBox
pnlAttrs.Controls.Add(chkbxSel(i))
AddHandler chkbxSel(i).Click, AddressOf chkbxSelI_Click '< ??
Next
Private Sub chkbxSelI_Click(ByVal i As Integer)
MsgBox("bingo for number " & i.ToString)
End Sub
Any and all help will be appreciated.
Thanks, Bob