Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted
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.
Posted

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

Software bugs are impossible to detect by anybody except the end user.
Posted

You might also want to add some handles to some events...

 

Take a peak at the AddHandler method...

Software bugs are impossible to detect by anybody except the end user.
Posted

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.

Posted

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

Software bugs are impossible to detect by anybody except the end user.
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...