Yos Wibowo
asked on
Duplicating a tab page content to another in TabControl control
Hi...
I'm a beginner in VB. Currently I'm using VB in VS 2015. I've search in the internet how to duplicate a tab page content to another in TabControl control. But I ended up on the basic terminology between TabItem and TabPage, which I found it confusing.
Can someone explain this a little bit when to use each object, especially that relates to goal to duplicate the page to another programmatically.
Thanks in advance.
Yos
I'm a beginner in VB. Currently I'm using VB in VS 2015. I've search in the internet how to duplicate a tab page content to another in TabControl control. But I ended up on the basic terminology between TabItem and TabPage, which I found it confusing.
Can someone explain this a little bit when to use each object, especially that relates to goal to duplicate the page to another programmatically.
Thanks in advance.
Yos
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi PNRT,
Thanks for the reply.
I followed your step, but it still doesn't work...
FYI, I use wpfapplication form for my project in VS 2015 (probably this makes the difference).
And as I compiled, error occurs "BC30456 'SelectedTab' is not a member of 'TabControl'."
Any suggestion?
Thanks,
Yos
Thanks for the reply.
I followed your step, but it still doesn't work...
FYI, I use wpfapplication form for my project in VS 2015 (probably this makes the difference).
And as I compiled, error occurs "BC30456 'SelectedTab' is not a member of 'TabControl'."
Any suggestion?
Thanks,
Yos
Public Shared Function TryCloneElement(Of T)(orig As T) As T
Try
Dim s As String = Markup.XamlWriter.Save(orig),
stringReader As New IO.StringReader(s),
reader As XmlReader = XmlTextReader.Create(stringReader, New XmlReaderSettings())
Return DirectCast(Markup.XamlReader.Load(reader), T)
Catch
Return DirectCast(DirectCast(Nothing, Object), T)
End Try
End Function
Using:
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim newTab = TryCloneElement(TabItem1)
If Not newTab Is Nothing Then
TabControl1.Items.Add(newTab)
End If
End Sub
yes, you didn't mention that you were using WPF. I'll take a look.
PS. To replace existing tab with copy:
Dim newTab = TryCloneElement(TabItem1)
If Not newTab Is Nothing Then
TabControl1.Items.Remove(TabItem2) 'remove second tab
TabControl1.Items.Insert(1, newTab) 'Insert copy instead of TabItem2
End If
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Ark,
I'd prefer to use UserControl as it seems more flexible to put other controls in it (thanks for your suggestion...).
I can follow the idea, but when I try to add tab with "newtab.Controls.add(....) ", error occurs "BC03456 'control' is not a member of 'TabItem'."
Regards,
Yos
I'd prefer to use UserControl as it seems more flexible to put other controls in it (thanks for your suggestion...).
I can follow the idea, but when I try to add tab with "newtab.Controls.add(....)
Private Sub MainWindow_Activated(sender As Object, e As EventArgs) Handles Me.Activated
Dim currDir As String = "E:\Project\Data\"
Dim filelines() As String = File.ReadAllLines(currDir & "Region.txt")
Dim newtab As New TabItem
newtab.control.add 'error occurs : BC03456 'control' is not a member of 'TabItem'
End Sub
Is there anything that I missed?Regards,
Yos
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, Ark & PNRT for your guidance...really helpful...
I'm learning from you guys...
Yos
I'm learning from you guys...
Yos
I found this to be the easiest way around this problem in VB.Net
Assuming your Tabcontrol is TabControl1
First: add a panel control (Panel1) to the tab that you wish to duplicate
Second: Include all the controls that you have in that tab to Panel1
Now add this code to your form -
Open in new window
This will add the controls in Panel1 to whichever Tab you require when that tab is selected