在消息框中显示列表框中的项目

本文关键字:项目 列表 显示 消息 | 更新日期: 2023-09-27 18:07:04

我正在编写一个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 +…(直到列表结束)

谢谢你的帮助!

在消息框中显示列表框中的项目

您可以使用selecteitem . tostring()。

str.AppendLine(selectedItem.ToString());

修改

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

str.AppendLine(selectedItem.ToString())