I have a form with nested tab controls. We're trying to make the application keyboard-friendly, thus when you're accessing the inner tab control, we'd like Control-Tab to cycle through the inner tabs. For the most part this works. Starting here with the focus in TextBox A....
Control Tab will take us to the next tab as expected, with the focus in TextBox B:
Fantastic, just what we wanted. If "Gamma" and "Delta" are similar, I go right around back to Alpha again with Control-Tab.
However, we have a few tabs where all of the controls are inside of group boxes. This causes all kinds of problems. If I take the same example, but put the text box inside of a group box. Starting here with the focus in the TextBox A again:
Control-tab takes us to the next tab as we'd expect. (Curiously, the focus isn't anywhere visible...)
But then Control-tab again takes us to...
Speculation: This is because the tabbing from Alpha (with groupboxes) to Beta (with groupboxes) left Beta with no control with focus. The focus returned to the tab control itself (AlphaBetaGammaDelta) and Control-Tab was passed to the outer tab control (OneTwoThreeFour).
Now, I can fix this by catching the SelectedIndexChanged event for the inner tab control, and manually focusing the first focus-able control inside that tab each time it changes, but that seems so wrong and a maintenance headache if the controls get moved around.
// Works, but I'm not crazy about it.
private void tabControlABGD_SelectedIndexChanged(object sender, EventArgs e)
{
switch(tabControlABGD.SelectedTab.Name)
{
case "tp_A":
tb_a.Focus();
break;
case "tp_B":
tb_b.Focus();
break;
case "tp_G":
tb_g.Focus();
break;
case "tp_D":
tb_d.Focus();
break;
}
}
Messing with the "tab order" of the form -- no effect whatsoever.
What's the right way to fix this?
Instead of a switch, try to simply call the SelectNextControl method:
void tabControlABGD_SelectedIndexChanged(object sender, EventArgs e) {
this.SelectNextControl(tabControlABGD, true, true, true, true);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With