WinForms: SelectedIndexChanged event does not fire when the user tabs off of an open DropDownList ComboBox

Article ID: 948869
Expand all | Collapse all
Source: Microsoft Support

RAPID PUBLISHING

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

Action

If a Windows Forms form contains a DropDownList ComboBox control and the user drops down the list and tabs away from the control.

Result

The item the user had hovered over will be saved but the SelectedIndexChanged event does not fire.

Cause

This is a bug in the underlying comctl32.dll (v6), which handles the themed ComboBoxes.  Tabbing off of an item in the DropDownList the ComboBox is supposed to cancel the selection, and it correctly fires a CBN_SELENDCANCEL notfication and not the CBN_SELENDOK notification which WinForms wraps in the SelectedIndexChanged event.  The problem is that instead of reverting to the prior selection it "reverts" back to the same new selection. 

Resolution



This can be worked around by forcing the ComboBox closed when tabbing off, which forces the selection to be changed fully before it can be "cancelled".

public class MyComboBox : ComboBox
{
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.Tab)
this.DroppedDown = false;
return base.ProcessDialogKey (keyData);
}
}

DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.

Properties

Article ID: 948869 - Last Review: February 7, 2008 - Revision: 1.0
Keywords: 
kbnomt kbrapidpub KB948869

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