2012-03-14 50 views
0

我有Listbox1多選擇mod。現在我想要,當選擇該列表框中的項目傳遞它們時。 Listbox位於form1上,當在form2旁邊單擊以在form2上的標籤中顯示我在Listbox form1中選擇的項目時。c#將列表框中的選定項目傳遞給另一個表格

試過這種

foreach (var item in listBoxSobe.SelectedItems) 
{ 
    lblSobe.Text += (lblSobe.Text == "" ? "" : ", ") + item.ToString(); 
} 

但結果我得到 「System.Data.DataRowView ..」,而不是點擊物品從Control

+0

因爲你傳遞的是對象而不是價值。嘗試添加strItem = item.ToString();並將strItem傳遞給lblSobe.text而不是item – Brian 2012-03-14 14:38:19

+0

@Brian這是因爲item的類型爲'DataRowView',而不是因爲傳遞對象。 – 2012-03-14 14:43:56

回答

1

也許是這樣的:

foreach (DataRowView item in listBoxSobe.SelectedItems) 
{ 
    lblSobe.Text += (lblSobe.Text == "" ? "" : ", ") + item["TheColumnYouWant"].ToString(); 
} 
+0

這是一個工作。謝謝 – user1269240 2012-03-14 15:10:45

+0

很高興幫助。也許你可以接受答案呢? – Arion 2012-03-14 15:12:20

+0

對不起我是新的 如果這是「這篇文章對你有用嗎?」我點擊是:p – user1269240 2012-03-14 20:42:01

相關問題