FIX: The LostFocus event is raised before the GotFocus event when you press the TAB key to change the focus to a ComboBox control in the .NET Framework 1.0

Article translations Article translations
Article ID: 813031 - View products that this article applies to.
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

Symptoms

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.

Cause

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.

Resolution

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:
http://www.microsoft.com/downloads/details.aspx?familyid=6978D761-4A92-4106-A9BC-83E78D4ABC5B&displaylang=en

Status

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.

More information

Steps to reproduce the behavior

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project. The New Project dialog box appears.
  3. Under Project Types, click Visual Basic Projects.
  4. Under Templates, click Windows Application.
  5. 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.
  6. Add a TextBox control and a ComboBox control to the Form1 form.
  7. Right-click the ComboBox control, and then click Properties.
  8. In the Properties window, set the DropDownStyle property to Simple or to DropDown.
  9. 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.
  10. 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:
      1. Locate the following code in the Form1.vb file.
        End Class
      2. 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 Sub
        Private 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:
      1. Locate the following code in the Form1.cs file.
        this.comboBox1.Name = "comboBox1";
      2. 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);
      3. Add the following code after the Main procedure.
        private void comboBox1_GotFocus(object sender, System.EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("comboBox1_GotFocus");
        }
        private void comboBox1_LostFocus(object sender, System.EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("comboBox1_LostFocus");
        }
  11. On the Build menu, click Build Solution.
  12. On the Debug menu, click Start. Press TAB.
In the Output window, you can see that the LostFocus event of the ComboBox control occurs before the GotFocus event.

References

For more information about ComboBox events, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.combobox_events(vs.71).aspx
For more information about the DropDownStyle property, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.combobox.dropdownstyle(vs.71).aspx
For additional information, click the following article number To view the article In the Microsoft Knowledge Base:
824684 Description of the standard terminology that Is used To describe Microsoft software updates

Properties

Article ID: 813031 - Last Review: November 1, 2013 - Revision: 2.0
Applies to
  • Microsoft .NET Framework 1.0
Keywords: 
kbnosurvey kbarchive kbcontrol kbnetframe100presp3fix kbcombobox kbqfe kbhotfixserver kbfix kbbug KB813031

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com