Experts Exchange connects you with the people and services you need so you can get back to work.
ComboBox SelectedItem, SelectedValue, SelectedWhat???
ComboBox has a lot of helpful properties that allow you to get access to items selected by the Control. The problem is knowing which one is best in which scenario. The documentation is not 100% clear on what the values will be in various situations. The most important factor to know is whether or not you are DataBinding in the ComboBox.
In this case the properties will have the following values
SelectedItem - For gets this will return the actual object in the DataSource that is being displayed in the ComboBox. For sets if the value exists in the DataSource, it will be selected, otherwise the operation will complete without an exception but won't actually do anything.
SelectedValue - This property depends on the value of ValueMember.
If the property ValueMember is not Nothing the ComboBox will look for a member on SelectedItem with the name specified in ValueMember and return that. This is also the value displayed in the ComboBox.
If the property ValueMember is Nothing, then the SelectedValue will return .ToString() on the SelectedItem
SelectedIndex - Index of SelectedItem in the DataSource
SelectedItem - Gets and Sets both go to the currently selected object from the Items collection
SelectedValue - Will be Nothing/null
SelectedIndex - Index in the Items collection of the SelectedItem
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $12.50.
Premium members get this course for $159.20.
Premium members get this course for $79.20.
Premium members get this course for $151.20.
Premium members get this course for $95.20.
Premium members get this course for $174.99.