How to display the same control on two different tabs?
Solution 1
If you don't need design-time support you can simply, at runtime, change the ListBox instance's Parent from one tab to the other (making sure to set the positioning appropriately, of course).
Essentially, it's:
listBox1.Parent = tabControl1.TabPages[1];
In the end though, you'll probably find it easier to just have two ListBox's with the same data source.
Solution 2
Yes, I think you'll need a ListBox control on each tab. If they have the same data you can use the same DataSource for both though.
Solution 3
Yes, add a new instance on each tab.
Solution 4
If you want full designer support, you'll need two boxes. If doing it in code is enough, you can create a single listbox on form load, and manually add a reference to it to each tab page.
Admin
Updated on July 29, 2022Comments
-
Admin almost 2 years
I'm using VB.NET
I need same control (ListBox) to be displayed on 2 different tabs.
Is it mandatory to create 2 different ListBox instances?
-
Larry almost 9 yearsThat's the way to do :) I had to cope with a similar situation where different usercontrol instances had to be displayed in tabs, plus a same single control instance which had to appear on every tab. I used the same
.Parent
property trick as you, using a Panel placeholder inside the control instead of the TabPage : it works fine. -
beppe9000 about 8 yearsI did not expect it to be this simple to move a tabpage between tabcontrols :)