By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,136 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,136 IT Pros & Developers. It's quick & easy.

Know which dynamically added control was clicked

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.