473,414 Members | 1,716 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,414 software developers and data experts.

How to get which dynamically created label was clicked...

!NoItAll
297 100+
I am creating multiple labels on a form dynamically. Essentially then they become an array.

Label(0)
Label(1)
Label(2)
etc...

I am also adding a handler for each one
Expand|Select|Wrap|Line Numbers
  1. Addhandler label(I).Click, AddressOf ShowPix
  2.  
The sub "ShowPix" is common to all of them because I do not know how many labels will be created.

So now inside of Showpix

Expand|Select|Wrap|Line Numbers
  1. Private Sub ShowPix()
  2.     'how do I determine which dynamically created label sent the click event...
  3. End Sub
  4.  
  5.  
So how do I determine which label the click event came from?

I have tried Me.ActiveControl.tag (I previously set the tag for each label appropriately - but that doesn't always work.
Jan 28 '12 #1

✓ answered by jhirsch41

using the correct signature of a click handler solves the problem, for example:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ShowPix(Byval sender as Object, Byval e as EventArgs)
  2.      Dim lbl as Label = CType(sender, Label)
  3.      Dim lblName as String = lbl.Name 
  4. End Sub
  5.  
etc.......

2 6099
using the correct signature of a click handler solves the problem, for example:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ShowPix(Byval sender as Object, Byval e as EventArgs)
  2.      Dim lbl as Label = CType(sender, Label)
  3.      Dim lblName as String = lbl.Name 
  4. End Sub
  5.  
etc.......
Jan 28 '12 #2
!NoItAll
297 100+
Thanks jhirsch41!
That works a treat! I was playing with that a bit, but was attempting to only use the "sender as object" part - which appears to not give it the correct signature - so it was a mess. Your solution does exactly what I needed! Thanks again!
Jan 28 '12 #3

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

Similar topics

7
by: mef526 | last post by:
I would like to reference a dynamically created control and I know the name. I would like to use the following: Dim strName as String = "txtControl1" ' This is the ".Name" used when textbox was...
7
by: rsaffy | last post by:
I am having trouble with my dynamically created button's event handling. I read that the buttons need to be recreated on every trip to the server, but how exactly do you do that when the datagrid...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
1
by: anniejacob | last post by:
Hi, I got Form F1 which consists of one label and on click of this label it creates a new form F2 with three dynamically created buttons(the number of button to be created is passed from the label...
1
by: stimul8d | last post by:
okay; ASP. I have i listbox inside a user control which is dynamically created on page_init. I check for postback and only populate the datasource if it's false. regardless, i do this ...
1
by: André | last post by:
Hi, Three labels are dynamically created. If a certain condition is met, then label 2 must be hidden. My problem: if the condition is met, with this code here below, there remains a gap between...
1
by: karthik25 | last post by:
Hi, The following code creates a tab container, 5 tab panels, buttons, labels. I was able to add event handlers to the button. But how am i supposed to access the dynamically created labels? For...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
2
by: savianand | last post by:
I want to know the code how to save data from dynamically created textboxes. The code I have written is this in whch I have dynamically created label and textboxes in a html table.The data in the...
4
by: pooja8389 | last post by:
Good evening.. how can i save the value of dynamically created textbox in data base using System; using System.Data; using System.Configuration; using System.Collections; using...
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
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
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...
0
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,...
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...
0
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...

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.