如何获取列表框中所选项目的值?WPF Listbox SelectedItems
我想是这样的:
foreach (var item in combo_course_op.SelectedItems)
{
string s = "select cid from tms_course where course_title = '" + item.ToString() + "'";
}
但它不works..it显示字符串s为“选择tms_course其中COURSE_TITLE = 'System.Data.DataRowView' CID”
我在哪里做错了?
这是我的数据怎么绑定:
MyCommand = new OdbcCommand("select distinct module_name from tms_class_schedule where class_date ='"+selectedDate+"'", DBConnect.MyConnection);
dap = new OdbcDataAdapter(MyCommand);
DS = new DataSet();
dap.SelectCommand = MyCommand;
dap.Fill(DS);
combo_course_op.DataContext = DS.Tables[0].DefaultView;
combo_course_op.DisplayMemberPath = DS.Tables[0].Columns["module_name"].ToString();
我试过了,但还没有运气;我编辑了这个问题,请查看 – iJay
您是如何收到物品的。 (即combo_course_op.SelectedItems类型) – Tilak
嗨tilak, 我将列表框更改为列表视图。我认为我的数据绑定方法有一些错误。 列表 moduleNames = new List (); (MyReader.Read()) while(MyReader.Read()) { moduleNames.Add(MyReader.GetString(0)); } combo_course_op.ItemsSource = moduleNames; 现在你的方法很好... :) –
iJay