BUG: The Text property retains a previous value when you type the first character in a bound ComboBox (814346)
The information in this article applies to:
- 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
- Microsoft Visual Studio .NET (2003), Academic Edition
- Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2003), Professional Edition
SYMPTOMSYou bind a ComboBox control to the Datasource property, and then set the DisplayMember property of the ComboBox. The Text property of the ComboBox returns the previously selected item when you type the first
character in the TextChange event. Thereafter, the Text property returns the correct value.CAUSEWhen you type the first character in the TextChange event, the SelectedItem property is not changed in the ComboBox. The ComboBox receives the previously selected item from the list. After you
type the first character, the TextChanged event is fired. The ComboBox updates the SelectedIndex property after you set the values for TextChanged and SelectedItem to null, and you set the value for SelectedIndex to -1. If SelectedItem is absent, the WindowText property is retrieved. Therefore, the problem behavior only
occurs one time.WORKAROUNDTo work around this problem, use the Value property of the AccessibleObject class instead of using the Text property of the ComboBox as follows: Microsoft Visual Basic .NET CodeSystem.Diagnostics.Debug.WriteLine("Text typed in ComboBox is : " + ComboBox1.AccessibilityObject.Value) Microsoft Visual C# .NET CodeSystem.Diagnostics.Debug.WriteLine("Text typed in ComboBox is : " + ComboBox1.AccessibilityObject.Value); Note To use AccesibleObject, add a reference to the Accessibility assembly. STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.REFERENCES
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
327244
BUG: ComboBox does not clear when you set SelectedIndex to -1
Modification Type: | Minor | Last Reviewed: | 1/21/2006 |
---|
Keywords: | kbvs2005applies kbvs2005doesnotapply kbvs2002sp1sweep kbWindowsForms kbDataBinding kbControl kbComboBox kbCtrl kbbug KB814346 kbAudDeveloper |
---|
|