Roshan Roshan - 3 months ago 14
C# Question

How to get the selected item of a combo box to a string variable in c#

Can anyone tell me how to get the selected item of a combo box to a string variable?

string selected = cmbbox.SelectedItem.ToString();
MessageBox.Show(selected);


This gives me
System.Data.DataRawView
in my messageBox

Answer

Try this:

string selected = this.ComboBox.GetItemText(this.ComboBox.SelectedItem);
MessageBox.Show(selected);