Reputation: 982
how can i pick up the values from list view column, lets suppose I've following list view
Product Quantity Product price Total Price
2 4 8
3 4 12
2 5 10
now i want to pick values in Total Price
column and add them all, means i want to add 8,12,10. how can i do it?
Upvotes: 0
Views: 3043
Reputation: 5324
You can get a ListViewItem
by iterating through the collection ListView.Items
.
Each ListViewItem
with more than one value has SubItems that are collected in the ListViewItem.SubItem
-Collection.
decimal sum = 0;
foreach (ListViewItem item in listView1.Items)
{
string _val = item.SubItems[2].Text;
decimal totalPrice = decimal.Parse(_val);
sum += totalPrice;
}
Upvotes: 0
Reputation: 26209
private void button1_Click(object sender, EventArgs e)
{
int totalPrice = 0;
for(int i=0;i<listView1.Items.Count;i++)
{
totalPrice += Convert.ToInt32(listView1.Items[i].SubItems[2].Text);
}
}
Upvotes: 2