473,385 Members | 1,942 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,385 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 6095
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
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...

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.