Article ID: 327555 - Last Review: May 11, 2007 - Revision: 3.5 BUG: The Text property of a data-bound ComboBox returns an incorrect value when you set the value in codeThis article was previously published under Q327555 On This PageSYMPTOMS If you programmatically set the Text property for a data-bound member of the ComboBox control, the value typed in the text box portion of the ComboBox is displayed as expected. However, the Text property and the SelectedIndex property incorrectly return the value of the last item that was
selected in the list box instead of returning the value typed in the text box.
When you type in the ComboBox at runtime, Text property returns the typed value, and SelectedIndex returns a value of -1. RESOLUTION To resolve this problem, set the SelectedIndex property to -1 before you set the Text property for a data-bound member of the ComboBox, as in the following examples. Visual Basic .NETVisual C# .NETFor example, if you bind the DisplayMember property and the ValueMember property of the ComboBox to a list that contains the numbers 1 through 10, and you want the ComboBox to display the number 5 in the text box and show 5 as selected in the list, you must set the SelectedIndex property to 5. STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
MORE INFORMATIONSteps to Reproduce the Behavior
APPLIES TO
| Article Translations
|
Back to the top
