1
votes

I have a Windows Forms GUI that has a bunch of controls, one of which is a FlowLayoutPanel containing a group of RadioButtons.

I can tab to the first RadioButton (TabIndex and TabStop set properly), but when I hit tab again it takes me to the next control on the form, not the next radio button in the FlowLayoutPanel.

Once the first RadioButton has focus, the only way to go through the group is to use up/down arrows, but that actually selects the RadioButton. Selecting a RadioButton kicks off some other stuff, so I just want a way to tab through the list to figure out what to select.

What I want, ideally, is to have each RadioButton act like any other control on the page and allow me to tab through the whole group without selecting a RadioButton until I hit Space.

1

1 Answers

0
votes

This tab order is default Windows behaviour and it is rarely good practice to change this.

It happens as the Radio Buttons in a group have TabStop juggled to work this way.

To change this, explicitly set the Tab Stop to true every time it is reset:

public Form1()
{
    InitializeComponent();

    foreach (var control in this.flowLayoutPanel1.Controls.OfType<RadioButton>())
    {
        control.GotFocus += (s,a) => SetTabStops(flowLayoutPanel1);
        control.CheckedChanged+= (s,a) => SetTabStops(flowLayoutPanel1);
    }
}

private static void SetTabStops(Control host)
{
    foreach (Control control in host.Controls)
    {
        control.TabStop = true;
    }
}