I have a form with a group of dropdowns that I want to keep out of the tab order in some cases. I've set the TabStop property to false and I set it to true when I want them to be in the tab order. I always want to include them all in the tab order when a user clicks on one of the dropdowns in that group. To accomplish this, I'm setting the TabStop property of all the dropdowns to true in an Enter event handler for each of the controls. This produces strange behavior on Enter. Each of the controls appears to have all of its text selected (highlighted). I would expect only the control that has focus to behave like that. Can anyone explain this? Thanks!
I created a simple form that has the same strange behavior. When the form comes up, just click on either of the dropdowns with your mouse and this is what you'll see:
Here's the code for the Form in C#:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void comboBox1_Enter(object sender, EventArgs e)
{
comboBox1.TabStop = comboBox2.TabStop = true;
}
private void comboBox2_Enter(object sender, EventArgs e)
{
comboBox1.TabStop = comboBox2.TabStop = true;
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"comboBox1",
"comboBox2"});
this.comboBox1.Location = new System.Drawing.Point(12, 12);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 1;
this.comboBox1.TabStop = false;
this.comboBox1.Text = "comboBox1";
this.comboBox1.Enter += new System.EventHandler(this.comboBox1_Enter);
//
// comboBox2
//
this.comboBox2.FormattingEnabled = true;
this.comboBox2.Items.AddRange(new object[] {
"comboBox1",
"comboBox2"});
this.comboBox2.Location = new System.Drawing.Point(12, 39);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(121, 21);
this.comboBox2.TabIndex = 2;
this.comboBox2.TabStop = false;
this.comboBox2.Text = "comboBox2";
this.comboBox2.Enter += new System.EventHandler(this.comboBox2_Enter);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 77);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.ComboBox comboBox2;
}