TabIndex is not working properly

I have a windows application. There are three group fields on the form. Each group package contains some controls. See Image. form

There is a groupbox flag that contains several flags. "flag" is inside "groupbox1". I used the Tab key to go through each control, but it does not work for checkboxes in the "flag". I set the correct tabindex for each control.

It works for text fields and buttons, but checkboxes.

Why? Thanks for the help.

EDIT

// groupBox2 // this.groupBox2.Controls.Add(this.pictureBox10); this.groupBox2.Controls.Add(this.pictureBox9); this.groupBox2.Controls.Add(this.pictureBox8); this.groupBox2.Controls.Add(this.pictureBox7); this.groupBox2.Controls.Add(this.chkStoplight); this.groupBox2.Controls.Add(this.lblStoplight); this.groupBox2.Controls.Add(this.chkIsCount); this.groupBox2.Controls.Add(this.chkExceptionFlag); this.groupBox2.Controls.Add(this.chkIsActive); this.groupBox2.Controls.Add(this.lblIsActive); this.groupBox2.Controls.Add(this.lblExceptionFlag); this.groupBox3.Controls.Add(this.lblIsCount); this.groupBox2.Location = new System.Drawing.Point(16, 201); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(321, 70); this.groupBox2.TabIndex = 10; this.groupBox2.TabStop = true; this.groupBox2.Text = "Flags"; // // chkStoplight // this.chkStoplight.AutoSize = true; this.chkStoplight.Location = new System.Drawing.Point(44, 25); this.chkStoplight.Name = "chkStoplight"; this.chkStoplight.Size = new System.Drawing.Size(15, 14); this.chkStoplight.TabIndex = 0; this.chkStoplight.UseVisualStyleBackColor = true; In the property, I found TabStop is true for chkStoplight. 
+7
source share
2 answers

For System.Windows.Forms.GroupBox :

You must make sure that your GroupBox flag has the appropriate TabIndex set.

From MSDN - How to customize tab order in Windows Forms :

In addition, by default, a GroupBox control has its own TabIndex value, which is an integer. The GroupBox control itself cannot have focus at run time. Thus, each control in a GroupBox has its own decimal TabIndex value, starting with .0. Naturally, as the TabIndex GroupBox controls grows, the controls inside it will be accordingly. If you change the TabIndex value from 5 to 6, the TabIndex value for the first control in its group automatically changes to 6.0, etc.

Also, make sure the TabStop property of your GroupBox flag not set to false. I believe false is the default value.

For System.Windows.Controls GroupBox :

Make sure the GroupBox.IsTabStop property is set . It is also false by default.

Update: It looks like all your controls are being added to groupBox3 . You must make sure that each of them is added only to its containing group box. For example, checkBox1 , checkBox2 and checkBox3 should be added to the flag , which should be added to groupBox1 . groupBox3 should only contain Back, Next, Finish, and Cancel. Strike>

+9
source

I found that the only way to get the order of tabs in WinForms groups is to change the order in which controls are added to the group fields in the generated InitializeControl method.

If you have multiple group boxes, you will need to check the order in which group fields are added to your container, and possibly change it.

I really dislike editing the generated code, but as far as I can see, this is the only way to fix this.

Setting the TabStop property to the group field did not help.

+1
source

All Articles