Home Dashboard Directory Help
Search

Wrong SelectedItem in DropDownClosed event handler of ComboBox when pressing Tab to leave an opened dropdown by Helen Zhou


Status: 

Closed
 as Won't Fix Help for as Won't Fix


2
0
Sign in
to vote
Type: Bug
ID: 680361
Opened: 7/22/2011 1:15:17 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
2
Workaround(s)
view
1
User(s) can reproduce this bug

Description

DropDownClosed event got random SelectedItem in ComboBox when type an item's text and press Tab to leave the control. That means SelectedItem in DropDownClosed event is not the one as in Leave event .

If using mouse to choose the item other than TYPING in combobox, then the random disappear, both DropDownClosed and Leave event get the same SelectedItem as expected.
Details
Sign in to post a comment.
Posted by Microsoft on 7/22/2011 at 1:50 PM
Thank you for reporting this issue. Customer feedback is a critical part of a successful, impactful software product. Unfortunately another part is the reality of schedules and the need to prioritize investments according to the objectives of the product. We have evaluated the issue that you have reported and at this point in the product's lifecycle, it does not meet the criteria to be addressed. This evaluation is carefully done and considers many aspects including the cost of the fix, implications of the change, and the number of reported instances of the issue.


Many customers have found it useful to discuss issues like this in the forums (http://www.microsoft.com/communities/forums/default.mspx) where Microsoft and other members of the community can recommend ways of achieving the behavior you are interested in.
Posted by MS-Moderator10 [Feedback Moderator] on 7/22/2011 at 2:15 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 7/22/2011 at 1:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Fred Hanson on 8/20/2012 at 7:03 PM
An "update" to my previous workaround:

//as noted here: https://connect.microsoft.com/VisualStudio/feedback/details/523272/combobox-does-not-display-selectedvalue-to-user-in-windows-7
//Windows 7 has issues with ComboBoxStyle.DropDownList mixed with AutoCompleteMode.Append or AutoCompleteMode.SuggestAppend
//this class seeks to address those problems
public class BetterComboBox : ComboBox
{
private int _windows7CorrectedSelectedIndex = -1;

private int? _selectedIndexWhenDroppedDown = null;
protected override void OnDropDown(EventArgs e)
{
    _selectedIndexWhenDroppedDown = SelectedIndex;
    base.OnDropDown(e);
}
private bool _onDropDownClosedProcessing = false;
protected override void OnDropDownClosed(EventArgs e)
{
    if (_selectedIndexWhenDroppedDown != null && _selectedIndexWhenDroppedDown != SelectedIndex)
    {
     try
     {
        _onDropDownClosedProcessing = true;
        OnSelectionChangeCommitted(e);
     }
     finally
     {
        _onDropDownClosedProcessing = false;
     }
    }
    base.OnDropDownClosed(e);
    if (SelectedIndex != _windows7CorrectedSelectedIndex)
    {
     SelectedIndex = _windows7CorrectedSelectedIndex;
     OnSelectionChangeCommitted(e);
    }
}
protected override void OnSelectionChangeCommitted(EventArgs e)
{
    if (!_onDropDownClosedProcessing) _windows7CorrectedSelectedIndex = SelectedIndex;
    _selectedIndexWhenDroppedDown = null;
    base.OnSelectionChangeCommitted(e);
}
protected override void OnSelectedIndexChanged(EventArgs e)
{
    bool alreadyMatched = true;
    if (_windows7CorrectedSelectedIndex != SelectedIndex)
    {
     _windows7CorrectedSelectedIndex = SelectedIndex;
     alreadyMatched = false;
    }
    base.OnSelectedIndexChanged(e);

    //when not dropped down, the SelectionChangeCommitted event does not fire upon non-arrow keystrokes due (I suppose) to AutoComplete behavior
    //this is not acceptable for my needs, and so I have come up with the best way to determine when to raise the event, without causing duplication of the event (alreadyMatched)
    //and without causing the event to fire when programmatic changes cause SelectedIndexChanged to be raised (_processingKeyEventArgs implies user-caused)
    if (!DroppedDown && !alreadyMatched && _processingKeyEventArgs) OnSelectionChangeCommitted(e);
}
private bool _processingKeyEventArgs = false;
protected override bool ProcessKeyEventArgs(ref Message m)
{
    try
    {
     _processingKeyEventArgs = true;
     return base.ProcessKeyEventArgs(ref m);
    }
    finally
    {
     _processingKeyEventArgs = false;
    }
}
}
Posted by Fred Hanson on 3/23/2012 at 7:52 AM
Try this:
//as noted here: https://connect.microsoft.com/VisualStudio/feedback/details/523272/combobox-does-not-display-selectedvalue-to-user-in-windows-7
//Windows 7 has issues with ComboBoxStyle.DropDownList mixed with AutoCompleteMode.Append or AutoCompleteMode.SuggestAppend
//this class seeks to address those problems
public class BetterComboBox : ComboBox
{
private int _windows7CorrectedSelectedIndex = -1;

protected override void OnSelectionChangeCommitted(EventArgs e)
{
    _windows7CorrectedSelectedIndex = SelectedIndex;
    base.OnSelectionChangeCommitted(e);
}

protected override void OnSelectedIndexChanged(EventArgs e)
{
    _windows7CorrectedSelectedIndex = SelectedIndex;
    base.OnSelectedIndexChanged(e);
}

protected override void OnDropDownClosed(EventArgs e)
{
    base.OnDropDownClosed(e);
    if (SelectedIndex != _windows7CorrectedSelectedIndex) SelectedIndex = _windows7CorrectedSelectedIndex;
}
}
File Name Submitted By Submitted On File Size  
CPPAutoComplete.rar 7/22/2011 40 KB