views:

1072

answers:

1

I have a VB.NET (2005) application designed by my boss that uses a over 100 input and display controls (textboxes, comboxes, etc.), many with labels associated. My boss asked me to set the tab order, and then trap keypress so the user can use enter to navigate controls. I have 2 apps like this to work on.

For the tab order, I could not use the View/TabOrder feature, since there are so many blue little tabindex popups showing, that I can not see any of the controls on the form to click. I tried clicking 'through' the popup with some success, but it still did not give me the tab order I wanted. The tab assistant that came with CodeSMART did not give me the result I wanted, either, so I could use it.

The controls on this usercontrol are spread among many groups, which in turn are spread among several splitcontainer panels. The 1st panel in the main splitcontainer has 3 main groupboxes which are selected via a toolstripbutton ( which sets the desired groupbox to visible and turning the others to invisible.)

Example:

Private Sub ShowMainPanel()
    'Note: Panels are groupboxes
    Me.MaterialPanel.Visible = False
    Me.HaulPanel.Visible = False
    Me.MainPanel.Visible = True

End Sub

Each of these groupboxes contain more groupboxes, each of which contain 1 to 15 controls. Some are read only, but others need information from the user. The required controls have their tab stop set to true.

So I MANUALLY set each of the main group panels tabindexes as 0 thru 2. Then for the 1st groupbox(mainpanel), I set the tabindex for each of it's controls and groupboxes that are contained within. The non-container type controls have their tabindexes set to 0 thru 25, and then the groupboxes (sub groups) on the mainpanel are 26 thru 48. I then went to each control in these sub groups and set tab index for those controls starting at 0 thru Control.count-1 for the group.

In summary, my tab orders look like this (abbreviated):

mainPanel = 0 1st fields = 0.0 2ndfield = 0.1 3rd field = 0.2 1st group = 0.3 1st field in 1st grp1 = 0.3.0 2nd field in 1st grp1 = 0.3.1 2nd group = 0.4 1st field in 1st grp2 = 0.4.0 2nd field in 1st grp2 = 0.4.1 materialPanel = 1 1st fields = 1.0 2ndfield = 1.1 3rd field = 1.2 1st group = 1.3 1st field in 1st grp1 = 1.3.0 2nd field in 1st grp1 = 1.3.1 2nd group = 1.4 1st field in 1st grp2 = 1.4.0 2nd field in 1st grp2 = 1.4.1

Note: I did not actually enter, for instance, 1.4.0 for a tabindex, but 0 for the control, 4 for the sub group and 1 for main group.

I then set the zorder via the Document Outline panel in based on the tab order.

Once I did all of this I was finally able to get the tab order I wanted to work for the mainpanel.

But when I applied the same to the other 2 groupboxes (materialPanel and haulpanel), the tabs are completely ignored. Tab does not work at all within the app. for the 2nd to main groupboxes (MaterialPanel and HaulPanel). The app is Control Library so I use the built in UserTestContainer when debugging, and when one of the 2nd 2 groupboxes are showing, the tab key moves the focus out of the app and into the test container.

This does not happen when on the 1st groupbox (MainPanel). IT works fine.

Setting this stuff out took me about 3-4 hours to tedious work. Due to the number of controls, this application is hard to work with, as anytime a change is made to the form designer, it takes a good 15-20 seconds to process it.

Does anyone have a clue about what's going on here?

Thanks.

Marshall Youngblood

A: 

It sounds like the GroupBoxes are being assigned the last tab index on the form so the next viable option for input focus is the form itself, which is the test container in this case.

Can you just capture the KeyPreview event? Cancel the key press and then just use an internally maintained collection of the order of controls to give focus. Given the number of controls it seems like you should be doing most of this in code anyway. Maintenance will be much easier if you use the .Controls property of the Groupbox/Panel and handle focus by iterating over that collection and finding the exact control you want.

Jacob Ewald
The Usercontrol does not handle the Keypreview event at all. I might be able to do late binding after I discover 'who' the parent will be, but I'm not sure that will work. Best I can do is add a generic KeyPress event handler that lets me send a tab key when a return key is pressed, but each control had to be listed in the handles list. I had to create 4 or 5 separate KeyPress events to keep it halfway readable. My interim solution was to number each control, including containers, with a unique tabindex in order, which seems to work. But I would have thought my original solution would work.
Marshall