Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListBox multiple Selection get all selected values

I'm having a problem since a while now an just can't find any solution that works for me. I have a ListBox which is filled up with a DataTable like

listbox.DataSource = table;  
listbox.Displaymember = "Name";    
listbox.ValueMember = "ID";

If I now select an item in my listbox I can get it out like:

listbox.SelectedValue.toString();

My Problem:

What can I do if I would like to have ALL selected Values from a ListBox where multiple selection is enabled and save them all in an array or something like that?!

I can't use SelectedItems cause that is not giving me the information I need.

like image 594
Mr. Toast Avatar asked Mar 14 '23 11:03

Mr. Toast


1 Answers

Try this:

var lst = listBox1.SelectedItems.Cast<DataRowView>();
foreach (var item in lst)
{
     MessageBox.Show(item.Row[0].ToString());// Or Row[1]...
}
like image 61
Salah Akbari Avatar answered Mar 31 '23 19:03

Salah Akbari