如何獲取列表框中所選項目的值?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