Can anyone tell me how to get the selected item of a ComboBox
to a string
variable?
string selected = cmbbox.SelectedItem.ToString(); MessageBox.Show(selected);
This gives me System.Data.DataRowView
in my MessageBox
To add items to a ComboBox, select the ComboBox control and go to the properties window for the properties of this control. Click the ellipses (...) button next to the Items property. This opens the String Collection Editor dialog box, where you can enter the values one at a line.
Try this:
string selected = this.ComboBox.GetItemText(this.ComboBox.SelectedItem); MessageBox.Show(selected);
You can use as below:
string selected = cmbbox.Text; MessageBox.Show(selected);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With