在消息框c#中显示所有列表视图项

本文关键字:列表 视图 显示 消息 | 更新日期: 2023-09-27 18:17:46

我有一个带有子项的列表视图。前5个子项目是名称、项目、总价、地址和电话。

其余的子项包含我为我的订单显示的过去列表。

这是一个披萨店程序,我希望它能够获得客户信息和订单。

我可以得到信息,但不能得到订单的其余部分。

如果有意义的话,我想知道如何显示我订单的其余部分。

订单例子:

Name: Claud
Items: 3
Total: 10.99
Address: (Blank)
Telephone: (Blank)
Order: Small Pizza
       -Bacon
       BreadSticks

现在我的消息框是这样的:

Name: Claud
Items: 3
Total: 10.99
Address: (Blank)
Telephone: (Blank)
Order: Small Pizza

所以我只想让它显示-Bacon and BreadSticks

源代码:

  private void CustomerInfo_Click(object sender, EventArgs e)
    {
        ListViewItem customers = new ListViewItem(fullName.Text);
        customers.SubItems.Add(totalcount.ToString());
        customers.SubItems.Add(total.ToString());
        customers.SubItems.Add(Address.Text);
        customers.SubItems.Add(telephone.Text);
        for (int i = 0; i < OrderlistBox.Items.Count; i++)
        {
            customers.SubItems.Add(OrderlistBox.Items[i].ToString());
        }
        Customers.Items.Add(customers);
        MessageBox.Show("Sent order for " + fullName.Text.ToString() + " to screen.");
        //CLEAR ALL FIELDS
        OrderlistBox.Items.Clear();
        fullName.Text = "";
        Address.Text = "";
        telephone.Text = "";
        totalDue.Text = "";
        totalItems.Text = "";
    }
    private void customerInformationToolStripMenuItem_Click(object sender, EventArgs e)
    {
        if (Customers.SelectedItems.Count != 0)
        {
            MessageBox.Show("Name: " + Customers.SelectedItems[0].SubItems[0].Text + "'n" +
                            "Adress: " + Customers.SelectedItems[0].SubItems[3].Text + "'n" +
                            "Telephone: " + Customers.SelectedItems[0].SubItems[4].Text + "'n" +
                            "Order: " +Customers.SelectedItems[0].SubItems[5].Text);
        }
    }

在消息框c#中显示所有列表视图项

您可以通过创建新的winform作为您的消息框来创建自定义消息框。在上面创建一个公共属性,传递你的selecteditems的值,比如:

然后在你的表单上:

 private void customerInformationToolStripMenuItem_Click(object sender, EventArgs e)
    {
        if (Customers.SelectedItems.Count != 0)
        {
            var myformmessagedialog = new MyFormMessageDialog
            {
name = Customers.SelectedItems[0].SubItems[0].Text,
adress=Customers.SelectedItems[0].SubItems[3].Text,
telephone=Customers.SelectedItems[0].SubItems[4].Text
              };
              myformmessagedialog.ShowDialog();
        }
    }
你MessageBoxDialogform:

MyFormMessageDialog : Form
{
  public MyFormMessageDialog()
    {
        InitializeComponent();
    }
    public string name;
    public string adress;
    public string telephone;
     private void MyFormMessageDialog_Load(object sender, EventArgs e)
    {
        lblName.Text = name;
        lbladdress.Text = adress;
        telephone.Text telephone;
       //if you are saving ado.net stuff 
       //query username where name = name then bind it on a list box or a combo box 
       var Orderdata = //you retrieve info via DataTable;
       lstOder.Items.Clear();
       foreach (DataRow data in Orderdata.Rows)
            {
                var lvi = new ListViewItem(data["Order"].ToString());
                // Add the list items to the ListView
                lstlstOder.Items.Add(lvi);
       }

    }
 }

希望这对你有帮助。关于