我有一个组合框,我是这样填充它的:
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";
}
}
}
我想要实现的是获取comboBox中选定项的数据,但是当我试图使用
MessageBox.Show(comboBox1.SelectedItem.ToString());
来显示它时,我得到的是类型System.Data.DataRowView.
而不是表category中字段描述的实际值。请帮忙解决...谢谢。
id
值,而不是描述... - yonan2236