Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: User-controls VB.NET
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 25-Feb-12 1:16am
Edited 25-Feb-12 1:17am
v2
Rate this: bad
good
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.
  Permalink  
Comments
SAKryukov at 26-Feb-12 2:59am
   
Agree, a 5.
--SA
Rate this: bad
good
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.
 
Thanks
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 27 Apr 2012
Copyright © CodeProject, 1999-2014
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