473,787 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting Button Events from Multiple manually instantiated controls

!NoItAll
297 Contributor
I have created a simple custom control - we will call it a "panel with buttons". Here is how I instantiate it:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim Panel(PanelCount) As Panel.Panel
  3. Dim iTop As Integer = 5
  4.  
  5.         For I As Integer = 0 To (PanelCount - 1)
  6.             Panel(I) = New Panel.Panel
  7.             Panel(I).Parent = Me
  8.             'the following just position the panels
  9.             Panel(I).Top = iTop + 10
  10.             iTop += 110
  11.             Panel(I).Left = 5
  12.         Next I
  13.  
So what I wind up with are multiple instances of my panel. Each of these panels has a button on it called Button1.
My question is - how do I capture this button event in a way that I will know which panel index it came from?

In the custom control there is only the Button1_click event - and when I click on it in any of the multiple panels I manually instantiated the event does occur, but I'm clueless as to how I can tell which one of my instantiated buttons were clicked...
Aug 30 '11 #1
1 1478
!NoItAll
297 Contributor
Ok - found the answer. I will try to post some sample code later but for now suffice to say that in my custom control I needed to create an event and then raise that event.
So I wound up doing something like:

Expand|Select|Wrap|Line Numbers
  1. Public Event ButtonPush(Index as Integer)
Then in the Button_Click event I put

Expand|Select|Wrap|Line Numbers
  1. RaiseEvent ButtonPush(CIndex(me.tag))
I will talk about the tag property in a minute...

In the form that is using my custom control there were a few things I needed to do:

When instantiating each control I need to set the tag property to an index (e.g. 0, 1, 2, 3, etc). This is the code I used:

Expand|Select|Wrap|Line Numbers
  1. Panel(I) = New Panel.Panel with {.Tag = I}
Now each panel has a unique tag which I will use as an index.

Next I needed to create a sub in my form to handle the event I wanted to catch

Expand|Select|Wrap|Line Numbers
  1. Sub PanelButtonPush_Clicked(Index as Integer) ' notice there is no Handles directive
  2.    'code to do something here
  3. End Sub
  4.  
Finally I needed to add the event handler so it would get processed in the message pump...

Expand|Select|Wrap|Line Numbers
  1. AddHandler Panel(I).PanelButtonPush, AddressOf PanelButtonPush_Clicked
Now whenever the button on any of the custom control array elements gets pushed the PanelButtonPush _Clicked event fires and the "Index" tells me which panel array element it came from.
Sep 1 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
5479
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and replacing it with a button of my own background color and text. The file paths I'd like displayed in a textarea and then the files uploaded at once.
3
3609
by: mitsura | last post by:
Hi, I have included a small listing. The test program opens a panel and show a bitmap. What I want is to when the mouse is over the bitmap panel, I want to trap the left mouse click. The purpose is to get the position of the mouse pointer on the bitmap. However, for some reason, the left (I also tried right) mouse clicks are not intercepted. I new to Python and wxWindows so any help would be greatly appreciated.
3
1893
by: Epetruk | last post by:
Hi, I'm trying to design a simple web form, but I cannot get the code in the btnSubmit_ServerClick event to fire. What am I doing wrong? Here's the codebehind: using System; using System.Collections; using System.ComponentModel;
0
1635
by: Pat Sagaser via .NET 247 | last post by:
I'm using a repeater with a dynamic template. I don't know the fields to display (or how many) until runtime. I have everything working except for linking Button events to the repeaters ItemCommand (see below). I've found plenty of examples for doing it using <ItemTemplate> in the aspx file, but I'm stumped when it comes to doing it dynamically at run time. /////////////////////////// .apsx file: <%@ Page language="c#"...
2
2232
by: JezB | last post by:
I'm adding WebControl objects to a Page dynamically on Page_Load, but I'm having trouble attaching events to these. For example, adding an image button :- ImageButton nb = new ImageButton(); nb.ImageUrl = "text.gif"; nb.ToolTip = "Edit Text"; nb.Click += new ImageClickEventHandler(b1_Click); myPlaceholder.Controls.Add(nb);
2
1544
by: Nathan Sokalski | last post by:
I have several Button controls that I created dynamically that I need to handle the Click events for. How do I specify the event handler for dynamically created controls? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
8
1170
by: CsaaGuy | last post by:
My button events stopped working on a aspx form. Dont' know why. any suggestions?
2
1463
by: acool | last post by:
I created this cool Usercontrol but now I am at a loss for how to access the events for the dynamic controls I created on the fly?
0
1099
by: Steve Moreno | last post by:
Hi all, I've got a web form that I've written code to create an array of DropDownList controls on the page depending on how many records are pulled back. The code to create the controls is working fine but now I need to add events to the newly created DropDownList controls. I need to add the SelectedIndexChanged event and I'm having a hard time getting the code to add events to the controls since the names (IDs) are varied to include...
1
1822
by: weboweb | last post by:
Hello aspnet experts! I have a design question for the more experienced developers (more than me at least :-)). 1) I have a page in the application I'm building that displays a web user control with a list of folders (let's call it the TREE) 2) There is another control called document list which shows the list of documents for the selected tree folder (let's call it DOCLIST)
0
9655
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
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...
1
10110
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
9964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.