How do I set a ComboBox default *not in the drop down* when a list item begins with the same text as a drop down item?

Posted by John Conrad on Stack Overflow See other posts from Stack Overflow or by John Conrad
Published on 2009-06-21T06:32:25Z Indexed on 2010/12/25 5:53 UTC
Read the original article Hit count: 455

Filed under:
|
|

Using C#, say you have a ComboBox that has a DropDownStyle set to DropDown (there are items in the drop down but the user can manually enter a value as well). How do you set a default value for the ComboBox that is not in the list of values in the drop down, but begins with text from a possible selection? Normally setting ComboBox.Text works fine, but if there is an item in the drop down that begins with the text you want as the default, it automatically selects the first item in the list that starts with the text. For example:

Values in the drop down:
c:\program files\
c:\windows\
d:\media\

Default Value Assignment
myComboBox.Text = "C:\";

Result
Initial value of ComboBox when the form opens is "c:\program files\".

So what am I doing wrong? How do I correctly set a default value of an item not in the drop down list that begins with a possible selection?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about gui