【问题标题】:c# pass selected items from listbox to another formc# 将列表框中的选定项目传递到另一个表单
【发布时间】:2012-03-14 14:33:48
【问题描述】:

我有带有多选模式的 Listbox1。 Now i want, when items in that Listbox are selected to pass them on next form.列表框在表单 1 上,单击表单 2 旁边的按钮以在表单 2 上的标签中向我显示列表框表单 1 中选择了哪些项目。

试过了

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

但结果我得到 "System.Data.DataRowView.." ,而不是从列表框中单击项目

【问题讨论】:

  • 因为您传递的是对象而不是值。尝试添加 strItem = item.ToString();并将 strItem 传递给 lblSobe.text 而不是 item
  • @Brian 这是因为项目的类型是DataRowView,而不是因为传递了对象。

标签: c# listbox


【解决方案1】:

可能是这样的:

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

【讨论】:

  • 对不起,我是新人,如果那是“这篇文章对您有用吗?”我点击是:p
  • 如果您在上下箭头旁边看到一个 V。如果您单击它,则表示您接受此答案作为问题的解决方案:-)
  • 您可以在这里阅读更多信息:meta.stackexchange.com/questions/5234/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-29
  • 1970-01-01
  • 1970-01-01
  • 2020-07-25
  • 1970-01-01
相关资源
最近更新 更多