簡體   English   中英

在消息框C#的列表框中顯示項目

[英]Display items in a listbox in a messagebox C#

我正在編寫一個Windows窗體應用程序,該應用程序要求我在消息框中打印列表框的項目。 這是我所擁有的:

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!");
}

結果,我收到一個帶有字符串的消息框,而不是列表中的項目,而是收到System.Windows.Forms.CheckedListBox +。 (直到列表末尾)

謝謝您的幫助!

您可能要使用selectedItem.ToString()。

str.AppendLine(selectedItem.ToString());

改變這個

str.AppendLine(ListBoxCondiments.Items.ToString())

入這個

str.AppendLine(selectedItem.ToString())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM