Reputation: 599
I am writing a windows form application that requires me to print the items of a listbox in a messagebox and well . . . here is what I have:
private void btnDisplay_Click(object sender, EventArgs e)
{
StringBuilder str = new StringBuilder();
foreach (object selectedItem in ListBoxCondiments.Items)
{
str.AppendLine(ListBoxCondiments.Items.ToString());
}
MessageBox.Show("Your made-to-order Burger will include:" + str, "Custom Burger!");
}
And as a result I am receiving a messagebox with string and instead of the items in my list I receive System.Windows.Forms.CheckedListBox + . . . (until the end of the list)
thank you for your help!
Upvotes: 1
Views: 5588
Reputation: 2614
Change this
str.AppendLine(ListBoxCondiments.Items.ToString())
Into this
str.AppendLine(selectedItem.ToString())
Upvotes: 0
Reputation: 13057
You would want to use selectedItem.ToString().
str.AppendLine(selectedItem.ToString());
Upvotes: 2