0
votes

I have Listbox1 with multiple selection mod. Now i want, when items in that Listbox are selected to pass them on next form. Listbox is on form1, when clicked next to form2 to show me in label on form2 what items are selected in Listbox form1.

tried this

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

but as result i get "System.Data.DataRowView.." , and not clicked items from Listbox

1
because you are passing the object and not the value. try adding strItem = item.ToString(); and pass strItem to the lblSobe.text instead of item - Brian
@Brian it's because item is of type DataRowView, not because of passing object. - Iarek

1 Answers

1
votes

Maybe something like this:

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