Clear Out, Reload Usercontrols in a Tab in VB.NET
Posted on 2009-05-06
I'm looking for some guidence to the best way to clear my tab form of dynamically generated UserControls, and then to reload it with the same UserControls (with different data, pulled from the database.
I load the controls like this:
For x = 0 To x
Dim cont As New NamesControl.ProductImage
AddHandler cont.SaveMyImage, AddressOf SaveMyImage
AddHandler cont.ChangeOrder, AddressOf ChangeOrder
contName = "id_" & x.ToString
cont.Name = "id_" & x.ToString
cont.Top = 100 * y
cont.Left = l
cont.LargeNameText = ImageArray(3, x)
cont.ThumbNameText = ImageArray(2, x)
cont.ImageOrderValue = ImageArray(4, x)
cont.idNum = ImageArray(0, x)
cont.msgText = ""
cont.ProdNameText = ProductName
contName = "http://www.mysite.com/image/" & ImageArray(2, x)
cont.ThumbImageFile = LoadWebImageToPictureBox(contName)
If x >= 5 Then
y = 0
l = 450
y += 1
l = 12
The usercontrol has 2 buttons - one for changing the order (fires the "ChangeOrder" event), and the 2nd for changing the image (fires the "SaveMyImage") event.
Since the UserControl is dynamically created, then loaded from the database, when the SaveMyImage event, or the ChangeOrder events are called, I need to update the database (which i can do), pull values from the database (which i can do) and then update the UserControls, which I can't seem to do.
The main issue I think is that I don't know how to refer to the UserControl that was clicked... When i tried "id_1" as the control name - VB.NET doesn't recognize it (i can understand why) but it returns an error and I can't compile/build/test. if the UserControl is loaded into the form, it should be available outside of the sub that created it, right?
Hope this isn't too confusing... thanks for your help!