473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

AddHandler etc.



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

Nov 21 '05 #1
5 1553
VJ
See Answers below..

"eBob.com" <eB******@totallyfakeisp.com> wrote in message
news:tj********************************@4ax.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.
- 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


Nov 21 '05 #2
VJ,

- 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
Was my thought as well, however I was first looking at your sample and than
saw this text.
For i As Integer = 0 To x
chkbxSel = New CheckBox
pnlAttrs.Controls.Add(chkbxSel)
AddHandler chkbxSel(i).Click, AddressOf chkbxSelI_Click
Next

AddHandler chkbxSel.Click, AddressOf chkbxSelI_Click

I assume just a typo, however to make it not to difficult for the OP.

Cor
Nov 21 '05 #3
EBob,

See bellow
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

I think that this will only go when it would be

For i As Integer = 0 To x
chkbxSel = New UNIQUEControl
pnlAttrs.Controls.Add(chkbxSel)
AddHandler chkbxSel.Click, AddressOf chkbxSelI_Click
Next

The original CheckBox has other parameters in his Click Event than your
UNIQUEControl so what you are doing now will not be accepted.

(You can use the array of course as well when you want afterwards use that
to set the properties of those checkboxes, however you can set those much
nicer in this loop and than you do not need the array as VJ already wrote.)

I hope this give the idea?

Cor
Nov 21 '05 #4
VJ
Yea thanks.. that was typo... And you have a good point, thanks I will keep
a note of it.

VJ

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
VJ,

- 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


Was my thought as well, however I was first looking at your sample and
than saw this text.

For i As Integer = 0 To x
chkbxSel = New CheckBox
pnlAttrs.Controls.Add(chkbxSel)
AddHandler chkbxSel(i).Click, AddressOf chkbxSelI_Click
Next

AddHandler chkbxSel.Click, AddressOf chkbxSelI_Click

I assume just a typo, however to make it not to difficult for the OP.

Cor

Nov 21 '05 #5

Gentlemen,

Thank you for your help.

Bob

On Wed, 16 Mar 2005 21:47:10 -0600, "VJ" <vi********@yahoo.com> wrote:
See Answers below..

"eBob.com" <eB******@totallyfakeisp.com> wrote in message
news:tj********************************@4ax.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.


- 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



Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: UGH | last post by:
I am adding image buttons dynamically and I need to add event handler when the user clicks on one of those image buttons which will have different id for reports. Here is my code LnkImage =...
1
by: Luis Esteban Valencia Muñoz | last post by:
Have a dropdownlist created in my LoadMain() which is called from the Page_load: ************************PAGE LOAD********************8Private Sub Page_Load(ByVal sender As System.Object, ByVal e...
4
by: DJ | last post by:
Good morning, Still new at this so please bear with me. I am creating a table dynamically using webcontrols based on the output of a sproc from my database.The table represents test instances...
2
by: Just Me | last post by:
When a document is to be printed I call a method that contains an AddHandler statement. I just realized that if a second copy is to be printed the method is called and the AddHandler is executed...
10
by: Rick Palmer | last post by:
I have an app I'm working on that will allow a user to run one of 5 reports. The report names are in a combobox on my form. I have a sub defined for each report that has the exact same name as is...
3
by: hartley_aaron | last post by:
Hi, I was trying to store the address of the my current handler for a particular event so as to simplify using AddHandler and RemoveHandler throughout my code. However, I cannot seem to get any...
2
by: TrtnJohn | last post by:
If you call AddHandler and hook events of one object to a method in a class will the event source object still be available for garbage collection if the original reference is set to Nothing? Or...
2
by: Joe | last post by:
Hello All: Can I wire server control events in the page's PreRender event and have them take effect? I am rendering LinkButtons in a Table on a webform and am using AddHandler to wire each...
5
by: Slim | last post by:
i have a simple page, with one button button1. when click it creates a new button button 2 and adds a event handler to it. but when button 2 is clicked nothing happens, why? Partial Class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.