I have a listView, in 1st column is are article names, in 2nd column are prices of these articles (data type of float).
And I have checkBoxes. What I would like to do, is to count the prices in 2nd column of all selected rows.
And then the counted value to show in a tectBox.
How can I do that?

This is what I did, but I dont know how to count them?

for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Checked)
                {
                    //when row checked is has to count here
                    //textBox1.Text += listView1.Items[i].SubItems[1].Text;
                }
            }

But this is not working correctly. It does not count prices together when selected the row.

And one more thing. Which method to use that the chekced rows will count in a real time.
An event handler "ItemCheck" it does not do that. It count the previous checked row when another is checked - so one step behind.

Edited 7 Years Ago by Mitja Bonca: n/a

float myPrice = 0F;             
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Checked)
                {
                    myPrice = float.Parse(listView1.Items[i].SubItems[1].Text;
                }
            }

I got a float number into variable "myPrice". How to SUM all which are selected together ( this + this + this..) and show the value in textBox1

Edited 7 Years Ago by Mitja Bonca: n/a

Got it, works great :)

float myPrice = 0F;             
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Checked && !String.IsNullOrEmpty(listViewLista.Items[i].SubItems[1].Text))
                {
                    myPrice = float.Parse(listView1.Items[i].SubItems[1].Text;
                }
                textBox1.Text = Convert.ToString(myPrice);
            }
This question has already been answered. Start a new discussion instead.