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

Know which dynamically added control was clicked

I have a form that creates a button for each employee in the database. I
have added the click handler and have this working. The buttons contain the
employee's name for their respective .Text and I have included a number in
the tag field. My problem is now, finding out which button is being clicked
so that I can pull the information from the database.

How can I get the tag value of the button clicked?

Also... what type of information can I store in the tag field of the
control? I would like to store the EmployeeID (which is generated by
MSAccess Autonumber) so that when the button is clicked, I can query the
database to get the information needed.

Thanks

Charlie

Jan 15 '08 #1
5 1783
On Jan 15, 10:41*am, "Charles May" <nu...@bidniz.comwrote:
I have a form that creates a button for each employee in the database. I
have added the click handler and have this working. The buttons contain the
employee's name for their respective .Text and I have included a number in
the tag field. My problem is now, finding out which button is being clicked
so that I can pull the information from the database.

How can I get the tag value of the button clicked?

Also... what type of information can I store in the tag field of the
control? I would like to store the EmployeeID (which is generated by
MSAccess Autonumber) so that when the button is clicked, I can query the
database to get the information needed.
In the Button Click event hander add a line:

Dim btn as Button = sender

Then you can reference all properties of the button that signalled the
event with the btn variable, as in btn.Tag.

Jan 15 '08 #2
Thanks Zacks

I knew it had something to do with sender but I couldn't figure it out.

Now you might be able to answer this for me.

Right now, I have a button on the form and when I click the button the new
buttons are created and added.

In my code I have the following

AddHandler btn.Click, AddressOf btn_Click

What I would like to do is generate everything while the frmSplash is up.
The only thing I am having a problem with is creating the handler on one
form to be used on another.

so frmSplash is displayed at startup and querys the database, then from
there creats the buttons on frmMain and creates the handler for the
btn_Click to work on frmMain when it is displayed.

Any ideas?

Thanks for all your help
Charlie

<za***@construction-imaging.comwrote in message
news:39**********************************@s8g2000p rg.googlegroups.com...
On Jan 15, 10:41 am, "Charles May" <nu...@bidniz.comwrote:
I have a form that creates a button for each employee in the database. I
have added the click handler and have this working. The buttons contain
the
employee's name for their respective .Text and I have included a number in
the tag field. My problem is now, finding out which button is being
clicked
so that I can pull the information from the database.

How can I get the tag value of the button clicked?

Also... what type of information can I store in the tag field of the
control? I would like to store the EmployeeID (which is generated by
MSAccess Autonumber) so that when the button is clicked, I can query the
database to get the information needed.
In the Button Click event hander add a line:

Dim btn as Button = sender

Then you can reference all properties of the button that signalled the
event with the btn variable, as in btn.Tag.
Jan 15 '08 #3
On Jan 15, 10:21 am, "Charles May" <nu...@bidniz.comwrote:
so frmSplash is displayed at startup and querys the database, then from
there creats the buttons on frmMain and creates the handler for the
btn_Click to work on frmMain when it is displayed.
frmSplash should not be querying the database. frmSplash should just
be informational only. Basically, in frmMain, you should show
frmSplash, then query the database and set up your buttons, finally
hide frmSplash and show frmMain. In other words, frmMain should be
the one that queries the database, creates the buttons, sets up the
event handlers for the buttons.

Chris
Jan 15 '08 #4
On Jan 15, 2:03*pm, Chris Dunaway <dunaw...@gmail.comwrote:
On Jan 15, 10:21 am, "Charles May" <nu...@bidniz.comwrote:
so frmSplash is displayed at startup and querys the database, then from
there creats the buttons on frmMain and creates the handler for the
btn_Click to work on frmMain when it is displayed.

frmSplash should not be querying the database. *frmSplash should just
be informational only. *Basically, in frmMain, you should show
frmSplash, then query the database and set up your buttons, finally
hide frmSplash and show frmMain. * In other words, frmMain should be
the one that queries the database, creates the buttons, sets up the
event handlers for the buttons.
I agree with Chris. Just close the spash form in the main form's load
event after it finishes creating all of the dynamic controls. The main
form's load event completes before the main form is actually shown.
Jan 15 '08 #5
Thanks Chris,
That's actually what I ended up doing. It was simpler and more easy for
following the code.

Thanks for the input though

Charlie
"Chris Dunaway" <du******@gmail.comwrote in message
news:d9**********************************@i12g2000 prf.googlegroups.com...
On Jan 15, 10:21 am, "Charles May" <nu...@bidniz.comwrote:
>so frmSplash is displayed at startup and querys the database, then from
there creats the buttons on frmMain and creates the handler for the
btn_Click to work on frmMain when it is displayed.

frmSplash should not be querying the database. frmSplash should just
be informational only. Basically, in frmMain, you should show
frmSplash, then query the database and set up your buttons, finally
hide frmSplash and show frmMain. In other words, frmMain should be
the one that queries the database, creates the buttons, sets up the
event handlers for the buttons.

Chris

Jan 15 '08 #6

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

Similar topics

7
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically...
5
by: MS Newsgroups | last post by:
Hi, I have a scenario where I am dynamically adding a control from code when a controls event is fired. The problem I have is that when the newly created control is clicked, the click event does...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
2
by: Quentin Huo | last post by:
Hi: I have a user control and I want to dynamically create a Label control and TextBox control when the button "add more author name" is clicked. I did like this: 1. there is a...
0
by: Dan | last post by:
hi, i have a page with two usercontrols: 1. a static menu control. 2. a dynamically loaded control as user interface the main page receives events from the menu and sets the apropriate ui...
1
by: keithb | last post by:
I have found that I must re-create dynamically added controls on every postback in order to find and access them programatically. The controls I am working with are inside a GridView control. When...
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...
7
by: =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?= | last post by:
I have a problem with accessing controls that I have loaded dynamically and added to a web page. The scenario: I have a webpage that displays multiple instances of a user control on the page. ...
1
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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.