This article has been archived. It is offered "as is" and will no longer be updated.
When you press the TAB key to change the focus to a ComboBox control, the LostFocus event of the ComboBox control is raised before the GotFocus event. This behavior occurs when the DropDownStyle property of the ComboBox control is set to Simple or to DropDown.
Note This problem also occurs when you change the focus to a form that contains the ComboBox control.
A ComboBox control that has the DropDownStyle property set to Simple or to DropDown has an inner Edit control. When you change the focus to the ComboBox control by using the TAB key, the focus is set to the ComboBox control, and then the focus is set to the inner Edit control. The LostFocus event is raised when the focus is set to the inner Edit control.
To resolve this problem, obtain the latest service pack for the Microsoft .NET Framework 1.0. To download the latest service pack, visit the following Microsoft Web site:
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section. This problem was first corrected in the Microsoft .NET Framework 1.0 Service Pack 3.
Steps to reproduce the behavior
Start Microsoft Visual Studio .NET.
On the File menu, point to New, and then click Project. The New Project dialog box appears.
Under Project Types, click Visual Basic Projects.
Under Templates, click Windows Application.
In the Name box, type MyApp, and then click OK. By default, one of the following files is created:
If you are using Microsoft Visual Basic .NET, a file that is named Form1.vb is created.
If you are using Microsoft Visual C# .NET, a file that is named Form1.cs is created.
Add a TextBox control and a ComboBox control to the Form1 form.
Right-click the ComboBox control, and then click Properties.
In the Properties window, set the DropDownStyle property to Simple or to DropDown.
In Solution Explorer, use one of the following procedures:
If you are using Visual Basic .NET, right-click Form1.vb, and then click View Code.
If you are using Visual C# .NET, right-click Form1.cs, and then click View Code.
Use one of the following procedures, depending on the programming language that you are using:
If you are using Visual Basic .NET, follow these steps:
Locate the following code in the Form1.vb file.
Add the following code before the code that you located in step a.
Private Sub ComboBox1_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.GotFocus System.Diagnostics.Debug.WriteLine("ComboBox1 GotFocus")End SubPrivate Sub ComboBox1_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.LostFocus System.Diagnostics.Debug.WriteLine("ComboBox1 LostFocus")End Sub
If you are using Visual C# .NET, follow these steps:
Locate the following code in the Form1.cs file.
this.comboBox1.Name = "comboBox1";
Add the following code after the code that you located in step a.
this.comboBox1.GotFocus += new System.EventHandler(this.comboBox1_GotFocus);this.comboBox1.LostFocus += new System.EventHandler(this.comboBox1_LostFocus);