I'm sure there is something simple that I am missing, but I must confess that at this point I am at a loss.
I am programmatically adding TabItems to my main TabControl, one for each account that the user chooses to open. Before creating and adding a new TabItem I would like to check if the user already has the account open in another tab. I do not want to end up with two identical tabs open.
Here is the code that I originally wrote. Hopefully it gives you an idea of what I am trying to accomplish.
if (tab_main.Items.Contains(accountNumber))
{
tab_main.SelectedIndex = tab_main.Items.IndexOf(accountNumber);
}
else
{
Search s = new Search(queryResults, searchText);
TabItem tab_search = new TabItem();
tab_search.Header = searchString;
tab_search.Name = accountNumber;
tab_search.Content = s;
tab_main.Items.Add(tab_search);
}
Of course this doesn't work properly. In WinForms the TabControl has a TabPages collection with a ContainsKey method that I could use to search for the name of the TabPage. I don't get what the Items.Contains() method is looking for since it only specifies an object as an argument and doesn't reference the item's name!
Any and all help is greatly appreciated.
Thanks!