autocalculate total value of items in listview when removing item using c#

后端 未结 3 805
旧时难觅i
旧时难觅i 2021-01-28 23:32

I\'m using a listview as a shopping cart. I need to know how to recalculate the total value of the cart when I remove an item.

Here is my code for adding to listview;

3条回答
  •  滥情空心
    2021-01-29 00:03

    private void btnRemoveItem_Click(object sender, EventArgs e)
    {
        int total = 0;
        foreach (ListViewItem item in lvCart.Items)
        {
           if (lvCart.Items[0].Selected)
            {
                total+=(int)lvCart.SelectedItems[0].SubItems[1].Text;//Add to total while romving
               lvCart.Items.Remove(lvCart.SelectedItems[0]);
               //total += Convert.ToInt32(item.SubItems[1].Text);
            }
        }
    
          rtbTcost.Text = total.ToString();
       }
    

提交回复
热议问题