The post is quite old but lacks a correct general answer which can
work regardless of the data-bound item type for example for List<T>
,
DataTable
, or can work regardless of setting or not setting
DisplayMember
.
The correct way to get text of an item in a ListBox
or a ComboBox
is using GetItemText
method.
It doesn't matter what is the type of item, if you have used DataSource
and DisplayMember
it uses DisplayMember
to return text, otherwise it uses ToString
method of item.
For example, to get a comma-separated list of selected item texts:
var texts = this.listBox1.SelectedItems.Cast<object>()
.Select(x => this.listBox1.GetItemText(x));
MessageBox.Show(string.Join(",", texts));
Note: For those who are looking for selected item values rather that selected item texts regardless of the item type and the value member field, they use GetItemValue
extension method.