ktos1234
ktos1234

Reputation: 207

ComboBox SelectedItem shows System.Data.DataRowView

I insert data from my database to combobox, and now I want to display value of this combobox into label, but every time instead of getting value of combobox, I get System.Data.DataRowView in my label.

I use this code for connection, it works fine:

OracleConnectionStringBuilder sb = new OracleConnectionStringBuilder();
sb.DataSource = "localhost";
sb.UserID = "library";
sb.Password = "library";
OracleConnection conn = new OracleConnection(sb.ToString());
conn.Open();
OracleDataAdapter TITLES = new OracleDataAdapter("SELECT NAME FROM TITLE", conn);
DataTable dt = new DataTable();
TITLES.Fill(dt);
cmbBooks.DisplayMember = "NAME";
cmbBooks.DataSource = dt;
conn.Close();

And then I want to get SelectedItem using this code:

label1.Text = cmbBooks.Items[cmbBooks.SelectedIndex].ToString();

How to solve it?

Upvotes: 0

Views: 1727

Answers (1)

Salah Akbari
Salah Akbari

Reputation: 39956

You can use the GetItemText method:

label1.Text = cmbBooks.GetItemText(cmbBooks.SelectedItem);

Upvotes: 4

Related Questions