troubleshooting Question

:: URGENT ::  Dynamically Created Controls at Run-Time.  Cannot access thier Index or assigned value (.TAG) property when clicked.

Avatar of afsanchez001
afsanchez001 asked on
Programming
10 Comments1 Solution461 ViewsLast Modified:
I have a panel (Panel1) which serves as my container, which houses a collection of tiled pictureboxes.  These pictureboxes are Dynamically Created as controls during Run-Time.  I use a nested For...Next environment to accomplish the Row-Column Tiling effect.  THAT IS NOT THE PROBLEM.

The problem is during the For...Next iteration (when I build the Dynamic Controls) I use:

AddHandler myPB.Click, AddressOf myPB_Click    <<-- This creates a Click Event for the newly created Control.

'--------------------------------------------------------------------------------------------------------------------
    Private Sub myPB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox(Panel1.GetContainerControl.ActiveControl.Tag)    <<-- Breaks here...
    End Sub
'--------------------------------------------------------------------------------------------------------------------

When I dynamically create TEXTBOXES the Click event gives me the (.TAG) information, but when I Dynamically create PICTUREBOXES (which is what I need to use) the GetContainerControl.ActiveControl.Tag RETURNS a NULL VALUE (Nothing) and breaks.

Any Ideas???

Is there a better way to detect which control I am clicking and successfully returning the Index or “assigned value” like in the .TAG property??
ASKER CERTIFIED SOLUTION
Mike Tomlinson
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros