0
我在從列表視圖中刪除項目時遇到問題。該程序計算列表中剩餘值的總值。問題是,當我刪除一個項目時,它刪除了在列表視圖中添加的第一個項目的值。在列表視圖中刪除項目和值
例如:
/*I added this items in order.
item1 = 20,
item2 = 10,
item3 = 5
When I remove item2 its rtbTcost is 15 based on the program below.
Which means that the value of item1 was removed.*/
int totalRemoved = 0;
for (int i = 0; i < lvCart.SelectedItems.Count; i++)
{
totalRemoved += int.Parse(lvCart.Items[i].SubItems[1].Text);
lvCart.Items.Remove(lvCart.SelectedItems[i]);
}
_listTotal -= totalRemoved;
rtbTcost.Text = _listTotal.ToString();