Question Adding ListBox to a new TabPage during run-time, control does not appear?

chess123mate

Member
Joined
Jan 29, 2010
Messages
5
Location
Canada
Programming Experience
5-10
I have a tabgroup with 2 tabs. During runtime, I wish to add new ones. Though I can get the tabs added, I cannot seem to add the ListBox that is supposed to go with it.
In the code below, I added '*' to indicate a line I added to try and fix the problem, but (obviously) don't work.
VB.NET:
Dim newTab As New TabPage("Group " + g.userLabel.ToString())
newTab.Name = "Tab" + g.userLabel.ToString
TabGroups.TabPages.Add(newTab)
lb = New ListBox()
lb.CreateControl() '*'
newTab.Select() '*'
newTab.BringToFront() '*'
newTab.Controls.Add(lb)
lb.BringToFront() '*'
Using lb
     Name = nam
     Size = ListBoxAll.Size 'ListBoxAll is the ListBox on the first tab
     Location = ListBoxAll.Location
     Visible = True '*'
     Enabled = True '*'
     Anchor = ListBoxAll.Anchor '*'
     lb.BorderStyle = ListBoxAll.BorderStyle '*'
End Using
registerLB(lb) 'Adds an event handler to it
I get the feeling this should have a simple answer...

Any help on this would be appreciated. Thanks,
chess123mate
 
VB.NET:
Using lb
     Name = nam
     Size = ListBoxAll.Size 'ListBoxAll is the ListBox on the first tab
     Location = ListBoxAll.Location
     Visible = True '*'
     Enabled = True '*'
     Anchor = ListBoxAll.Anchor '*'
     lb.BorderStyle = ListBoxAll.BorderStyle '*'
End Using
VB.NET:
With lb
    .Name = "nam"
    .Size = ListBoxAll.Size 'ListBoxAll is the ListBox on the first tab
    .Location = ListBoxAll.Location
    .Visible = True '*'
    .Enabled = True '*'
    .Anchor = ListBoxAll.Anchor '*'
    .BorderStyle = ListBoxAll.BorderStyle '*'
End With
Homework, right? Study on. :cool:
 
Back
Top