It's not the first control on the form, it's every combobox on the
form. Am I the only one who has this issue?
Here's some code to demonstrate the problem:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ComboBoxTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox cmb1;
private System.Windows.Forms.ComboBox cmb2;
private System.Windows.Forms.TextBox textBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
cmb1.SelectedIndex = 0;
cmb2.Text = "itemnull";
textBox1.Focus();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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.cmb1 = new System.Windows.Forms.ComboBox();
this.cmb2 = new System.Windows.Forms.ComboBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// cmb1
//
this.cmb1.Dock = System.Windows.Forms.DockStyle.Top;
this.cmb1.Items.AddRange(new object[] {
"item1",
"item2",
"item3"});
this.cmb1.Location = new System.Drawing.Point(0, 22);
this.cmb1.Name = "cmb1";
this.cmb1.Size = new System.Drawing.Size(402, 24);
this.cmb1.TabIndex = 0;
this.cmb1.Text = "comboBox1";
//
// cmb2
//
this.cmb2.Dock = System.Windows.Forms.DockStyle.Top;
this.cmb2.Items.AddRange(new object[] {
"item1",
"item2",
"item3"});
this.cmb2.Location = new System.Drawing.Point(0, 46);
this.cmb2.Name = "cmb2";
this.cmb2.Size = new System.Drawing.Size(402, 24);
this.cmb2.TabIndex = 1;
this.cmb2.Text = "comboBox2";
//
// textBox1
//
this.textBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.textBox1.Location = new System.Drawing.Point(0, 0);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(402, 22);
this.textBox1.TabIndex = 5;
this.textBox1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.ClientSize = new System.Drawing.Size(402, 358);
this.Controls.Add(this.cmb2);
this.Controls.Add(this.cmb1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
Notice that when you open the form, the textbox is focused, but cmb1 is
also highlighted . cmb2 is not highlighted because the text isn't in
the item list. If you set cmb2 text to an item in the Items list, it
too will be highlighted