Here the differences between the selection properties of a ComboBox
control.
- SelectedIndex;
- SelectedItem;
- SelectedText;
- SelectedValue.
The SelectedIndex
property :
Gets or sets the index specifying the currently selected item.
Simply indicates the index of the selected item in the selection list. (Information provided for your kind information only. =))
The SelectedItem
property :
Gets or sets currently selected item in the ComboBox
.
The SelectedItem represents the element that is currently selected as per the ListControl
of the ComboBox
. That is why this is what you want to use, to answer your question.
The SelectedText
property :
Gets or sets the text that is selected in the editable portion of a ComboBox
.
That is, when you edit the TextBox
portion of the ComboBox
, the text that might be selected when you enter for edit, or any other type of text selection. This indeed does include any selection made through the ListControl
portion of the ComboBox
. For instance, if your ComboBox.DropDownStyle
property is set to ComboBoxStyle.DropDownList
, then you will never be able to select any text in the editable portion of the ComboBox
. Despite, you're able to select another item within the its list. That is why it is not the right property to use to serve your purpose.
The SelectedValue
property :
Gets or sets the value of the member property specified by the ValueMember
property.
Only used when using DataBinding, in conjunction with the DisplayMember
property. For instance, when you want to display the name of a customer, and select him by his database Id, then the DisplayMember
should display the customer's name, and the ValueMember
the Id. This way, when you select one customer, the SelectedValue
changes and raises the SelectedValueChanged
event inherited from the ListControl
. (Information provided for your kind information only. =))