In ComboBox there are two properties, SelectedText and SelectedItem. SelectedItem property returns the currently selected object of the ComboBox. It can be any object. Use the ToString() method to get the string of the selected item if necessary. The SelectedText returns the editable text from the ComboBox. This property is only relavent when you set the ComboBox’s DropDownStyle to either Simple or DropDown. In these two cases, you will find that you can enter arbitrary text to the ComboBox. Then you can use SelectedText to return at any time the text in the ComboBox. If you set the ComboBox’s DropDownStyle to DropDownList, you will notice that you cannot enter text of your own. Instead, you can only select existing items from the list. In this case, at any time, SelectedText returns an empty string.
SelectedText will be useful when you want to implement your own style of suggestion list of the ComboBox. You will need to combine the usage of this property with the KeyPress event of the ComboBox.
Until next time, happy coding!
Recent Comments