BUG: The CheckedListBox control does not fire the KeyPress event when the key value is a space character (836676)



The information in this article applies to:

  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition

SUMMARY

The KeyPress event on the CheckedListBox control does not fire when the key value is a space character.

SYMPTOMS

When you run the application with a CheckedListBox control on the form, the CheckedListBox control does not fire the KeyPress event if the key value is a space character (the SPACEBAR on the keyboard).

CAUSE

The SPACEBAR is captured as an item that is being checked or unchecked in the CheckedListBox control. Therefore, the ItemCheck event of the CheckedListBox control fires.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section of this article.

MORE INFORMATION

Steps to reproduce the behavior

Create a new Microsoft Visual Basic Windows application

  1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  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, and under Templates, click Windows Application, and then click OK. By default, a form that is named Form1.vb is added to the project.

    Note In Visual Studio 2005, click Visual Basic.
  4. Add a CheckedListBox control to the Form1 form.

Add items to the CheckedListBox control

  1. Double-click the Form1 form to obtain the Form1_Load event.
  2. Add the following code in the Form1_Load event:
    Dim ItemObject(9) As System.Object
            Dim i As Integer
            For i = 0 To 9
                ItemObject(i) = "Item" & i
            Next i
            CheckedListBox1.Items.AddRange(ItemObject)

Add a handler for the KeyPress event

  1. In the code view of Form1.vb, click CheckedListBox1 in the first box.
  2. Click the KeyPress event from the second box that is provided in the Code view of Form1.vb. Notice that in the Code view of Form1.vb, the KeyPress event appears as follows:
    Private Sub CheckedListBox1_KeyPress(ByVal sender As Object,
        ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles CheckedListBox1.KeyPress
    
        End Sub
  3. Add the following code to the KeyPress event of the CheckedListBox1 control:
    MsgBox("KeyPress event fired")

Build and then run the application

  1. On the Build menu, click Build Solution.
  2. On the Debug menu, click Start.

Press the SPACEBAR on the keyboard while the CheckedListBox control is selected

After you run the application, the CheckedListBox control appears with the items that are populated in the CheckedListBox control. Follow these steps:
  1. Press the SPACEBAR on the keyboard while the CheckedListBox control is selected on the form. Notice that the KeyPress event is not fired.
  2. Press any other character keys from your keyboard. Notice that the KeyPress event is fired.

Modification Type:MajorLast Reviewed:2/28/2006
Keywords:kbvs2005swept kbvs2005applies kbvs2002sp1sweep kbpending kbCmnCtrls kbEvent kbbug KB836676 kbAudDeveloper