I have a combo box and I populated it this way:
DataTable dt = new DataTable();
using (SQLiteConnection conn = connection.Conn)
{
using (SQLiteCommand cmd = new SQLiteCommand(conn))
{
cmd.CommandText = "select id, description from category";
conn.Open();
using (SQLiteDataAdapter da = new SQLiteDataAdapter(cmd))
{
da.Fill(dtChargeCodes);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "description";
comboBox1.ValueMember = "id";
}
}
}
What I’m trying to achive is to get the data of the selected item in the comboBox but when I tried to display it using MessageBox.Show(comboBox1.SelectedItem.ToString()); what I get is the type System.Data.DataRowView. not the actual value of the field description in the table category. Please help… thanks.
Either use
or
You may need to use the second method if you need to access the value in the SelectedIndexChanged event (see here)