Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
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 27-Dec-11 12:20pm
Karim E407
Comments
Mika Wendelius at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Did you try the TabControl.SelectedIndex property? If you want to select the 3rd tab, it would go like this:
 
tabControl1.SelectedIndex = 2;
  Permalink  
Comments
Karim E at 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 at 30-Dec-11 9:24am
   
Create a two way binding for the SelectedIndex to your viewmodel
Espen Harlinn at 30-Dec-11 9:23am
   
5'ed!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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,
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 330
1 Sergey Alexandrovich Kryukov 279
2 BillWoodruff 245
3 Afzaal Ahmad Zeeshan 215
4 CPallini 205
0 OriginalGriff 5,635
1 DamithSL 4,496
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 28 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100