Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

combobox

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

like image 701
Roshan Avatar asked Mar 03 '13 13:03

Roshan


People also ask

Which method is used to add item in a ComboBox event?

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.


2 Answers

Try this:

string selected = this.ComboBox.GetItemText(this.ComboBox.SelectedItem); MessageBox.Show(selected); 
like image 162
Leo Chapiro Avatar answered Oct 06 '22 00:10

Leo Chapiro


You can use as below:

string selected = cmbbox.Text; MessageBox.Show(selected); 
like image 28
Omer Avatar answered Oct 05 '22 23:10

Omer