Reputation: 1149
I read all items from listbox:
StringBuilder sb = new StringBuilder();
foreach (object item in listBox1.Items)
{
{
sb.Append(item.ToString());
sb.Append(" ");
}
}
How read only selected items?
Upvotes: 0
Views: 179
Reputation: 8892
You can use the SelectedItems
Property to get all selected Items and then loop through them to append it to the string builder.
foreach (var listitem in listBox1.SelectedItems)
{
sb.Append(listitem.ToString());
sb.Append(" ");
}
Upvotes: 2