0

My client wants to have two separate tab lists on a form, but only one tab can be selected of the two tab lists. Can I create two TabControls to work like this? I.e. when one tab is selected at the first TabControl, the other should have all of their tabs deselected and vica versa.

EDIT:
This is what he imagined:enter image description here

monami
  • 594
  • 2
  • 9
  • 32
  • What do you mean by _deselecting_ a tab? – Aethan Nov 17 '16 at 00:03
  • Huh? There is always one TabPage in each TabControl active/selected. What do you mean by 'deselected'? It sounds like the design is flawed if stuff they are not supposed to be able to access yet can be. – Ňɏssa Pøngjǣrdenlarp Nov 17 '16 at 00:03
  • By deselecting I mean that no tabs of the TabControl would be in selected state. The content of the TabPage would be hidden, so the selection in any of the TabControl would display just a Panel below them. Cannot two TabControls be binded somehow? – monami Nov 17 '16 at 00:13
  • There is **always** one TabPage in each TabControl active/on top. what would it look like with all of them deselected? How can none of them be on top? – Ňɏssa Pøngjǣrdenlarp Nov 17 '16 at 00:32
  • Hmm, like the others, not highlighted? – monami Nov 17 '16 at 00:41
  • What do you mean by "on top"? – monami Nov 17 '16 at 00:43
  • Maybe you should add an image of what you think this should look like to your question. If you have 2 TabControls, there will always be 2 TabPages "selected". Now once a user physically clicks on one or the other, you could disable or hide the other TabControl (but what event would then allow it to be selected again?). – topshot Nov 17 '16 at 01:06
  • There is a reason you should not let users design UIs – Ňɏssa Pøngjǣrdenlarp Nov 17 '16 at 01:26
  • 1
    Create a wizard-like `TabControl` like the second one in [this post](http://stackoverflow.com/a/40633229/3110834), then have some `RadioButton` controls with `Button` style and select a `TabPage` based on selected `RadioButton`. Let me know if you had any problem applying the solution. – Reza Aghaei Nov 17 '16 at 02:30
  • @Plutonix you are right, I was just courious to know whether binding more tabcontrols to act like one is possible. I think I'll use labels and change their background when clicked, and display the content in a panel below them. – monami Nov 17 '16 at 12:09
  • Thanks @RezaAghaei, sounds promising, but I don't understand it exactly: where would I place the Radiobuttons? – monami Nov 18 '16 at 12:51
  • 1
    Radio buttons are above the tab control, like your screenshot, but the main point is in `TabControl`. Using panel will be painful. If you use panel you should manage showing and hiding them and also it would be hard to manage them at design time. Using a TabControl without header or some user controls is the best option. To see a header-less tab control take a look at my answer in linked post and use the second part of answer. – Reza Aghaei Nov 18 '16 at 13:59
  • I don't see any problem with adding and removing panels. In fact, the content of the TabPage is a custom Control and the legacy code adds and removes it already (this form had a combobox for categories). I think @topshot answer is the least complicated for me. Of course I appreciate your idea as well, many thanks! – monami Nov 20 '16 at 06:47

2 Answers2

1

Based on your image, I believe you should use RadioButtons. That limits selection to only 1 button but you can put them wherever you want. Then you could have a container that populates based on which button is selected.

enter image description here

topshot
  • 885
  • 6
  • 21
  • Hmm, thanks, this is very similar to my labels idea, but it sounds to solve the problem using the right controls properly. I'm trying this out! – monami Nov 18 '16 at 12:58
0

If I understand you correctly, you can put a tabcontrol(tabcontrol1) on a form. Add a tabpage for each set of pages you want to show.

On each tabpage, in tabcontrol1, add another tabcontrol and add however many pages you want in each.

To restrict access to a particular tab in tabcontrol1 set its enabled property to false;

Basically you'll end up with nested tabpages

Another option would be to create collections of tabpages that you could swap in and out of a single tabcontrol.

One way to get close to what you're pic shows is to use panels and put the tabcontrols inside them.

enter image description here

tinstaafl
  • 6,908
  • 2
  • 15
  • 22
  • Yeah, but nested tabs are not what I'm going for, but thanks :) I need two separate tabcontrols to handle their tabs as if they were one, so only one can have the selected tab at a time. – monami Nov 17 '16 at 00:40
  • @monami - By using the enabled property you can leave only one tabpage available at a time. You could also use collections of tabpages and swap them in and out as needed. – tinstaafl Nov 17 '16 at 00:47
  • I added the pic about what's been imagined, can you advise something on this? Enabled property in False still not deselect the active tab, just makes unable to select any of them. – monami Nov 17 '16 at 12:20
  • @monami - I came up with another idea, it still may not be 100% right but it's closer. – tinstaafl Nov 17 '16 at 15:59
  • OK, but this way the content is splitted and two tabs are selected at a time :( – monami Nov 18 '16 at 13:11