473,738 Members | 8,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Contro ls.Clear() will that undo the AddHandler or must
I use RemoveEventHand ler? And what would the syntax of the
RemoveEventHand ler be?

Here's the code ...

For i As Integer = 0 To x
chkbxSel(i) = New CheckBox
pnlAttrs.Contro ls.Add(chkbxSel (i))
AddHandler chkbxSel(i).Cli ck, 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 1576
VJ
See Answers below..

"eBob.com" <eB******@total lyfakeisp.com> wrote in message
news:tj******** *************** *********@4ax.c om...


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.Contro ls.Add(chkbxSel )
AddHandler chkbxSel(i).Cli ck, 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,Ch eckbox)
'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.Contro ls.Clear() will that undo the AddHandler or must
I use RemoveEventHand ler? And what would the syntax of the
RemoveEventHand ler 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.Contro ls.Add(chkbxSel (i))
AddHandler chkbxSel(i).Cli ck, 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.Contro ls.Add(chkbxSel )
AddHandler chkbxSel(i).Cli ck, 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.Contro ls.Add(chkbxSel (i))
AddHandler chkbxSel(i).Cli ck, 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.Contro ls.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******** ******@TK2MSFTN GP09.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.Contro ls.Add(chkbxSel )
AddHandler chkbxSel(i).Cli ck, 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********@yah oo.com> wrote:
See Answers below..

"eBob.com" <eB******@total lyfakeisp.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_Cli ck 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.Contro ls.Add(chkbxSel )
AddHandler chkbxSel(i).Cli ck, 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,Ch eckbox)
'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.Contro ls.Clear() will that undo the AddHandler or must
I use RemoveEventHand ler? And what would the syntax of the
RemoveEventHand ler 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.Contro ls.Add(chkbxSel (i))
AddHandler chkbxSel(i).Cli ck, 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
4020
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 = New ImageButton() LnkImage.ImageUrl = "~/printer.gif" LnkImage.ID = "ib" & oArray(1, id) AddHandler LnkImage.Command, AddressOf NewIbnCommandEvent()
1
2227
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 As System.EventArgs) Handles MyBase.Load Try 'Initialize. Main.SetBodyURL(Page) conSess = MySession.Connection(Session) objPP = MySession.ProdPres(Session, Req.ID(Request))
4
2369
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 that the test proctor who is viewing the page has currently assigned to him or heir. Each row of the table corresponds to a single test instance and includes required info about that test. At the end of the row I create a button control. Based on...
2
2766
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 again. Is doing AddHandler a second time wrong? I did check and even though I do AddHandler 3 times the handler is only called once.
10
5041
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 displayed in the combobox. I have one button on the form to start processing. What I want to do is this: When the user selects the report they want to run from the combobox, I want to dynamically bind the appropriate sub to the button's click...
3
5012
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 kind of variable to except the data. When I tried a Long I got the message "'AddressOf' expression cannot be converted to 'Long' because 'Long' is not a delegate type." I tried other datatypes as well but was not able to find anything that...
2
6500
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 do you have to call RemoveHandler as well? For example: I am using the ActiveX version of the WebBrowser control. In the DocumentComplete event I set up my event handlers for the Document object loaded by the browser. Do I have to call...
2
2279
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 LinkButton's click event to a private method in the page. The AddHandler calls are: AddHandler nameLink.Click, New System.EventHandler(AddressOf HandleLinkClick)
5
2206
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 test_buttons Inherits System.Web.UI.Page Dim bt2 As Button
0
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.