Gentlemen,
Thank you for your help.
Bob
On Wed, 16 Mar 2005 21:47:10 -0600, "VJ" <(E-Mail Removed)> wrote:
>See Answers below..
>
>"eBob.com" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>>
>>
>> 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.
>
>- Yes you can use one routinue.. it will work, you say Addressof
>Routine1_Click and attach it to all CheckBox's click event..
>
>>
>> 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.
>
>- You can have it in the Loop.. perfectly ok.. , regarding your syntax i am
>not sure why you are using array's.. the below do the trick
>
>For i As Integer = 0 To x
> chkbxSel = New CheckBox
> pnlAttrs.Controls.Add(chkbxSel)
> AddHandler chkbxSel(i).Click, AddressOf chkbxSelI_Click
> Next
>
> Private Sub chkbxSelI_Click(ByVal sender As Object, ByVal e As EventArgs)
> MsgBox("bingo for number " & i.ToString)
> End Sub
>
>>
>> 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.
>
> Private Sub chkbxSelI_Click(ByVal sender As Object, ByVal e As EventArgs)
> MsgBox("bingo for number " & i.ToString)
> CheckBox chk1 = Ctype(sender,Checkbox)
> 'Chk1 will give you the CheckBox that was clicked.. you can use the
>name to identify the box, or something in
> 'Check box tag to identify the box... I would prefer using name
> End Sub
>
>>
>> When I pnlAttrs.Controls.Clear() will that undo the AddHandler or must
>> I use RemoveEventHandler? And what would the syntax of the
>> RemoveEventHandler be?
>
>- Yes... u don't need to use RemoveHandler.
>
>>
>> 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
>>
>>
>>
>>
>>
>
|