
Change position of a tabpage on a tabcontrol????
Thanks for the response. I have found a way that you might be interested
in. I first declared a collection.
I use collection to store the tabpages in the order that I wanted them in.
Once I have them in the order I want them to be in,
I clear out the tabpages on the tabcontrol and then loop through the
collection and place them back on the tabcontrol.
I found this while doing some more research on the subject.
Here is the code that I used, I'm also changing the view in a treeview as
well, so that is why I have the treenode declare.
'Declare a clone of the selected node.
Dim objNode As TreeNode = Me.tvwProduct.SelectedNode.Clone
Dim colTabpages As New Collection()
Dim tpPage As TabPage
Dim i As Integer
'Declare a variable for the new and old indexes.
Dim intNewIndex As Integer
Dim intOldIndex As Integer = Me.tvwProduct.SelectedNode.Index
'Check if the old index is greater than one, if not then it is at the top of
the tree.
If intOldIndex > 0 Then
'Get the new index.
intNewIndex = intOldIndex - 1
'Remove the old node.
Me.tvwProduct.Nodes(0).Nodes(0).Nodes.RemoveAt(intOldIndex)
'Insert the cloned node into the position it is supposed to be.
Me.tvwProduct.Nodes(0).Nodes(0).Nodes.Insert(intNewIndex, objNode)
Me.tvwProduct.SelectedNode =
Me.tvwProduct.Nodes(0).Nodes(0).Nodes(intNewIndex)
Me.tvwProduct.SelectedNode.ExpandAll()
'Change the order of the tabpages (forms).
For i = 0 To Me.tabForms.TabPages.Count - 1
'Check if the form is at the new index.
If i = intNewIndex Then
'Swap the tabpages that is changing with the tabpage that it is
going to.
colTabpages.Add(Me.tabForms.TabPages(intOldIndex))
colTabpages.Add(Me.tabForms.TabPages(i))
i = intOldIndex
Else
colTabpages.Add(Me.tabForms.TabPages(i))
End If
Next
'Clear the tabcontrol of all tabpages.
Me.tabForms.TabPages.Clear()
'Add the tabpages back in the order that the user changed.
For i = 1 To colTabpages.Count
Me.tabForms.TabPages.Add(colTabpages.Item(i))
Next
Me.tabForms.SelectedTab = Me.tabForms.TabPages(intNewIndex)
End If
Quote:
> Todd,
> You are discovering the joys 8-( of using the Microsoft
> tab control. I have had problems with it also. The big
> problem you have is some how swapping all the controls on
> a tab page with another. You can use an array of panel
> controls, 1 per tab, additionally you can just swap the
> tab label names. Finally, when the user selects the tab
> of interest, vector through a mapping of tab to panel and
> paint the panel in all its glory. Never said it was easy.
> Pat
> >-----Original Message-----
> >I was wondering if anyone knew how to change the position
> of a tabpage on a
> >tabcontrol.
> >Say the tabcontrol has 3 tabpages on it. They are named
> tabpage1, tabpage2,
> >tabpage3 and ordered respectfully. I want the user to be
> able to press a
> >button on the page and move say tabpage 2 to the position
> that tabpage1 is
> >in. The new order would be tabpage2, tabpage1, and
> tabpage3.
> >I have not found a way to do this as of yet and can not
> seem to find any
> >samples that would help me in doing this, so if anyone
> could point me in the
> >right direction I would appreciate it.
> >Thanks,
> >Todd
> >.