【发布时间】:2014-02-16 14:17:19
【问题描述】:
我在从列表视图中删除项目时遇到问题。该程序计算列表中剩余值的总值。问题是当我删除一个项目时,它会删除列表视图中添加的第一个项目的值。
例如:
/*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();
【问题讨论】: