5 Answers, 1 is accepted
Thank you for the question.
The first thing when sorting tabs in RadTabStrip is to choose a criteria. I have prepared an example, which sorts the tabs based on their Text property. I have created a custom class that implements the IComparable interface. Then I put all the tabs into the array, sorted them with the Array.Sort() function, and returned them one by one back into my RadTabStrip's items collection. Please review the code-block provided below as a reference:
class ComparableTab : IComparable |
{ |
#region Properties |
private TabItem tabItem; |
public TabItem TabItem |
{ |
get |
{ |
return tabItem; |
} |
} |
private string tabItemText; |
public string Text |
{ |
get |
{ |
return tabItemText; |
} |
} |
#endregion |
#region Constructors |
public ComparableTab(TabItem tab) |
{ |
this.tabItem = tab; |
this.tabItemText = tab.Text; |
} |
#endregion |
#region IComparable Members |
public int CompareTo(object obj) |
{ |
if (obj is ComparableTab) |
{ |
ComparableTab tabItem2 = (ComparableTab)obj; |
return this.tabItemText.CompareTo(tabItem2.Text); |
} |
else |
{ |
throw new ArgumentException("Object is not a ComparableTab!"); |
} |
} |
#endregion |
} |
private void SortTabs(RadTabStrip radTabStrip) |
{ |
ComparableTab[] tabs = new ComparableTab[radTabStrip.Items.Count]; |
for (int i = 0; i < tabs.Length; i++) |
{ |
ComparableTab tab = new ComparableTab((TabItem)radTabStrip.Items[i]); |
tabs[i] = tab; |
} |
radTabStrip.Items.Clear(); |
Array.Sort(tabs); |
for (int i = 0; i < tabs.Length; i++) |
{ |
radTabStrip.Items.Add(tabs[i].TabItem); |
} |
} |
I hope this helps. If you need additional assistance, do not hesitate to contact me again.
Sincerely yours,
Martin Vasilev
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Did you know when you add them back, they will lose some of their visual properties?
I can find a work around to dispose the tabItems, and not lose valuable handles, but I'm can't figure out how to make the tabs retain this property:
tab.TextOrientation = Orientation.Horizontal;
You see, i have my tabs configurable. They can be "flipped" from either top or left positions. If the user currently has them on left position, and I excute the code below, the tabs will show up running down the left side, text going vertical. This is not what I want. Any suggestions.
I'm really suprised there isn't a simpler solution such as VisibleIndex within the tab control, so developers won't have to remove then add back the tabs in a new order.
thanks,
Brian.
Thank you for contact me again.
I have simplified my example by implementing the IComparer interface instead of ICompareble. You should not worry about the TabItem collection when you call the Clear() method, because they are reference types and there will not be a memory leak. Because of the same reason, you will not lose any settings, children controls, and event handlers for every single tab. I have prepared an example application that demonstrate this - you could find it attached. In addition, you could preview the code-block below as reference:
public class TabsComparer : IComparer |
{ |
#region IComparer Members |
public int Compare(object x, object y) |
{ |
if ((x is RadItem) && (y is RadItem)) |
{ |
return ((RadItem)x).Text.CompareTo(((RadItem)y).Text); |
} |
else |
{ |
throw new Exception("Provided objects is not a RadItem!"); |
} |
} |
#endregion |
} |
private void SortTabs(RadTabStrip radTabStrip) |
{ |
IComparer tabsComparer = new TabsComparer(); |
RadItem[] tabArr = radTabStrip.Items.ToArray(); |
Array.Sort(tabArr, tabsComparer); |
radTabStrip.Items.Clear(); |
radTabStrip.Items.AddRange(tabArr); |
} |
I hope this will better suit your scenario. If you have other questions, do not hesitate to contact me again.
Regards,
Martin Vasilev
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
radTabStrip.Items.Clear(); |
radTabStrip.Items.AddRange(tabArr); |
Have you tried this code? You lose visual settings, and you DO have a handle leak issue. I'm not sure about memory.
Try creating a tabstrip and place 3 tabs on the designer. make the tabs vertical, and place them on the left.
this.radTabStrip1.TabsPosition = Telerik.WinControls.UI.TabPositions.Left;
this.radTabStrip1.TextOrientation = System.Windows.Forms.Orientation.Vertical;
in a button click
RadItem test = radTabStrip1.Items[0];
radTabStrip1.Items.Clear();
radTabStrip1.Items.Add(test);
run program, and observe the USER Objects on this process through your task manager. Also note the position of the text.
Brian.
In the old version Q3 2007 SP1, there is a issue related to the TextOrientation property of RadTabStrip and you are right about the wrong behavior. However, this has been fixed in our new version Q1 2008. Please upgrade your project to Q1 2008 and download the example project in my previous post. It should work as in your scenario.
I hope this was useful to you. Do not hesitate to contact me again if you have other questions.
Sincerely yours,
Martin Vasilev
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center