Click here to Skip to main content
13,043,654 members (53,109 online)
Rate this:
Please Sign up or sign in to vote.
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
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
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 25-Feb-12 0:16am
Updated 25-Feb-12 0:17am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
SAKryukov 26-Feb-12 2:59am
Agree, a 5.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 27 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100