tverney Posted April 3, 2005 Posted April 3, 2005 There has to be a simple answer to this. I created a user control called ctlAuditDetailExpert in VB.Net. I can manually add it to a parent windows form successfully. The goal is to allow the user to add new instances of cltAuditDetailExpert at runtime. I attempted to add the user control as follows Sub Test(lpName as string) Dim ctl as New ctlAuditDetailExpert with ctl .location = New Point(50,50) .visible = true .show() .name = lpName end With End Sub The code run fine, no error messages but the newly added user control is not seen on the parent form. What am I missing? Quote
Mister E Posted April 3, 2005 Posted April 3, 2005 You have to add it to the parent form with the Controls.AddRange method. Also, in addition, you might consider using an array as a class member that holds the newly created instances of the controls (instead just using a variable with function-level scope). This will allow you to reference the object later. Quote
AlexCode Posted April 3, 2005 Posted April 3, 2005 Man... You're creating the control alright but you're missing the part where you tell where to put it!! Try adding domething like: Me.Controls.Add(ctl) That will work... Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
AlexCode Posted April 3, 2005 Posted April 3, 2005 You might also want to add some handles to some events... Take a peak at the AddHandler method... Quote Software bugs are impossible to detect by anybody except the end user.
tverney Posted April 3, 2005 Author Posted April 3, 2005 That works!! Thanks so much Man... You're creating the control alright but you're missing the part where you tell where to put it!! Try adding domething like: Me.Controls.Add(ctl) That will work... Alex :p Alex, thanks for the help! This was driving me nuts. Quote
AlexCode Posted April 3, 2005 Posted April 3, 2005 No swett... This can become a little harder when we need this kind of behaviour but at design-time... At Run-Time it's straight-forward! Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
tverney Posted April 4, 2005 Author Posted April 4, 2005 Thanks for pointing out the obvious You have to add it to the parent form with the Controls.AddRange method. Also' date=' in addition, you might consider using an array as a class member that holds the newly created instances of the controls (instead just using a variable with function-level scope). This will allow you to reference the object later.[/quote'] Mister E, Thanks thinking one step ahead of me when it came to the control collection. The obvious didn't come clear until later in the process; then I re-read your response. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.