tags:

views:

138

answers:

6

I have a form with 3 panels, the panels are created because at certain times I need certain groups of controls hidden/shown. Until now, it worked fine - that is until I was asked to have a specific way to navigate the form with TAB key.

First of all, I noticed that there is no TabIndex property in the Panel object and second of all (most important) - i don't want to follow a nested navigation algorithm, I just want to set my own sequence.

From what I read online so far, its not possible with panels - my only alternative is to put all the controls on the form in the same panel.....

Any thoughts? I don't feel like re-arranging the app, and start hiding and showing individual controls....

A: 

I think you're pretty much stuck there -- I don't know of any direct way to avoid that nested navigation.

I would, however, say that it's really not that big a deal to show/hide groups of controls:

private void SetPrimaryControlVisibility(bool visible)
{
  ctrlA.Visible = visible;
  ctrlB.Visible = visible;
  ctrlF.Visible = visible;
}

private void SetSecondaryControlVisibility(bool visible)
{
  ctrlC.Visible = visible;
  ctrlE.Visible = visible;
  ctrlG.Visible = visible;
}

It's a little more code writing -- but that took me 20 seconds. And if they're all on the form surface you can use the tab index.

Although now that I think about it, what's the problem with them on their own panel? If you're using panels to show/hide, then you aren't tabbing to the other panels anyway.

Another option would be to write key event handlers, but I'd stay away from that -- would be a huge unmaintainable mess.

Clyde
A: 

Pressing the TAB key will move the focus to the next control in the ControlCollection. Since the focus is always in a control within the Panel and not in the panel itself, how could you expect that a Panel supports tab index?

I suggest that you think again what you are trying to do. When a specific panel is visible, TAB should navigate you around the controls in it. It doesn't make sense for TAB to move you in the next panel. This is usually done with a button or some other control. Users expect that TAB moves the focus and not performing an action. Moreover, if you want to have TAB to move you around the panels, then you need to set the Tab Stop property of all controls to false.

kgiannakakis
A: 

thanks, I have an idea what the easiest way to do it.

kgiannakakis, one of my panels has a text field and a button in it. It just occured to me that removing a button from that panel will most likely solve this problem. Of course, I would have to write extra code to hode/show it...

gnomixa
A: 

actually one thing I don't understand.

say a panel has a label and a text box in it. When I view Tab order (with VS->View->Tab Order). I can see that the text box has a tab of 7.0. I understand that 7 means the order in which this control was added to the form, and 0 is the inner Tab order.

My question is, how do I set the tab order the way I want? Can I change the 7 (in the case above). It seems no matter what I do, the order is still different....Any ideas? Without re-doing the form that is.

gnomixa
A: 

i decided to get rid of the panels...

gnomixa
A: 

I had the same issue. My solution was to put all controls in subpanels on the form. The tabbing of .net algorithm is to tab within the 'current' container using the TabIndex. If any of the TabIndexes within a container are the same, the first one in z-order will be first, etc.

Once in a container (a form is a container), all controls other than containers(panels) are tabbed to first. When leaving the last non-container control the panels are recursed into.

Thus, if all controls are placed in containers/panels at the same level, your tabbing will be done as you expect.

Example Problem:

Form

  control1  Tabindex=1

  panel1

    control2 Tabindex=2

    control3 Tabindex=2

  panel2

    control4 Tabindex=4

    control5 Tabindex=5

  control6 Tabindex=6

Tabbing will be in the following order (not what you expected):

  Control1

  Control6  <-- not what you wanted/expected

  Control2

  Control3

  Control4

  Control5

To get it to tab correctly, layout in the following pattern:

Form

  panel0

    control1  Tabindex=1

  panel1

    control2 Tabindex=2

    control3 Tabindex=2

  panel2

    control4 Tabindex=4

    control5 Tabindex=5

  panel3

    control6 Tabindex=6
Scott