Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
How to determine which index a tab is at
posted

Hello,

I don't want to hardcode the indexes in my code to change between tabs.  I would like to be able to look-up the index number for a tab, then set that tab.  This allows me to change the order of my tabs without changing the navigation code.

There is an IndexOf(...) method in the TabItemCollection class.  But this takes a reference to a ContentTabItem.  However, there doesn't seem to be an ID property in the ContentTabItem, so there is no way that I can directly reference it.

As a workaround, here is the code that I have.  Is there an easier way to do this?

 

 

 

 

 

 

 

 

 

 

 

private

 

int FindTabIndex(string tabText)

{

 

TabItemCollection tabs = this.WebTabMain.Tabs;

 

for (int i = 0; i < tabs.Count; i++)

{

 

if (tabs[i].Text == tabText)

{

 

return i;

}

}

 

throw new ArgumentOutOfRangeException("tabText");

}