Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a question here.
Here's what,

- I have a usercontrol called ucDataUser.ascx
- I have a public sub to create new tabpage in tabcontorl
- The tabpage should be dynamically consist of ucDataUser
<pre lang="HTML">The code that I'd tried :
<pre="vb">Public Sub mainTabBaru(ByVal namaTab As String)
Dim c As New TabPage
c.Name = namaTab
If mainForm.TabControl1.TabPages.ContainsKey(namaTab) Then
mainForm.TabControl1.SelectTab(namaTab)
Else
mainForm.TabControl1.TabPages.Add(c)
c.Text = namaTab
Dim nama As String
nama = "uc" + Trim(namaTab)
Dim b As New UserControl
b.Name = nama
b.Parent = c
b.Dock = DockStyle.Fill
b.Show()
End If
End Sub</pre>

namaTab variable on that code should be dynamically change according to the usercontrol that I need to show on the tabpage.
But the result always new empty usercontrol from the code <code>Dim b as new usercontrol</code>.
How's that happen and how to fix it?</pre>
Posted
Updated 25-Feb-12 0:17am
v2

Two things.

It's a REALLY bad idea to call your control UserControl as that is already used as a class name in the .NET Framework. Your control should be called something a bit more descriptive.

You forgot to add the newly created contorl instance to the Controls collection of its parent container, like the tabpage you added.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Feb-12 2:59am    
Agree, a 5.
--SA
oh, this's old post.
and I've solved it properly (from programming view and user view of course ^^)

Next time I'll post how I solved it.

I'm too busy of making mobile game (and asking question here^^) lately. My appologize.

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900