Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have an WPF application (C#) where I have the following:
Multiple tab controls and each control have multiple tab items. I am trying to have the same tab item selected when switching between tab controls. all tabs are created dynamically.

Ex: if tabControl1 has tabItem3 selected then when you select tabControl2, tabItem3 is selected.

Thanks.
Posted
Comments
Wendelius 27-Dec-11 17:42pm    
So is the problem that the tabitem3 in tabcontrol2 gets selected or is that a desired feature and not working?
Karim E 27-Dec-11 20:22pm    
basically if tabitem3 is selected in tabcontrol1, the desired behavior is to have tabitem3 automatically selected when selecting tabcontrol2. Currently when selecting a different tabcontrol, the first tabitem is selected.

I am looking into figuring out a solution. May be someone has run into the same problem.

Did you try the TabControl.SelectedIndex property? If you want to select the 3rd tab, it would go like this:

C#
tabControl1.SelectedIndex = 2;
 
Share this answer
 
Comments
Karim E 28-Dec-11 9:35am    
Thanks John.
Unfortunately it is not that simple. Here is some clarification of the issue:

The tab controls are created dynamically and are located in the main window, the tab items are also created dynamically and are in a different module. Each tab control has several tab items.
selection changes in tab items level within one tab control works fine, but when switching to a different tab control, I haven't found an easy way to keep track of the tab item selection made in one tab control and set the same tab item selection in another tab control.
Espen Harlinn 30-Dec-11 9:24am    
Create a two way binding for the SelectedIndex to your viewmodel
Espen Harlinn 30-Dec-11 9:23am    
5'ed!
I did come up with a solution ( not very satisfied with it) but it does work.

Basically I created an index variable in the main module and used it to keep track of the tabItem selected under a specific tab control. Then used the saved index to select the tabItem whenever I select a different tabControl.

Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900