calculate subitems
-
how do i calculate subitems[4] * subitems[5] + all item in listview I tryade: Int value = 0; foreach (ListViewItem lvi in listView3.Items) { int.Parse(lvi.subtitems[4].ToString())*int.Parse(lvi.subtitems[5].ToString()) } label10.Text = value.ToString(); and i´m so wrong..!:^) do u have some suggests??:confused:
-
how do i calculate subitems[4] * subitems[5] + all item in listview I tryade: Int value = 0; foreach (ListViewItem lvi in listView3.Items) { int.Parse(lvi.subtitems[4].ToString())*int.Parse(lvi.subtitems[5].ToString()) } label10.Text = value.ToString(); and i´m so wrong..!:^) do u have some suggests??:confused:
This will not work definitely as value never changes and it is equal to zero all the time. Also, you are iterating over the items and calculating the same product. Instead you should sum them. You say that you need to calculate subitems[4] * subitems[5] but subitems of which items?
#region signature my articles #endregion
-
This will not work definitely as value never changes and it is equal to zero all the time. Also, you are iterating over the items and calculating the same product. Instead you should sum them. You say that you need to calculate subitems[4] * subitems[5] but subitems of which items?
#region signature my articles #endregion
calculate subitems[4] * subitems[5] + (next subitem[4] * subitem[5] for each subitems[4]*[5] like this: columnheader1,columnheader2,columnheader3,columnheader4,columnheader5,columnheader6, ........................................................................................3,5........... 100 .........................................................................................3,5.......... 100 the awnser should be: 700 tnx:cool:
-
calculate subitems[4] * subitems[5] + (next subitem[4] * subitem[5] for each subitems[4]*[5] like this: columnheader1,columnheader2,columnheader3,columnheader4,columnheader5,columnheader6, ........................................................................................3,5........... 100 .........................................................................................3,5.......... 100 the awnser should be: 700 tnx:cool:
I think you are attempting to do something like... int result = 0; foreach (lvi item in items) result += item.subitem[4] * item.subitem[5]; is this what you are attempting to do? I am really confused by how you get 700 from that example. Just ignore in your next post the fact that the numbers are subitems, and pretend like they are already integers so your problem becomes a bit more clear to the rest of us. -Jeff
-
I think you are attempting to do something like... int result = 0; foreach (lvi item in items) result += item.subitem[4] * item.subitem[5]; is this what you are attempting to do? I am really confused by how you get 700 from that example. Just ignore in your next post the fact that the numbers are subitems, and pretend like they are already integers so your problem becomes a bit more clear to the rest of us. -Jeff
-
subitem[4] is price/sides and subitem[5] are how many sides I wanna se the earned money..3,5*100 + 3,5*100 = 700 how do i pass the result to a label.text :doh::doh:
-
subitem[4] is price/sides and subitem[5] are how many sides I wanna se the earned money..3,5*100 + 3,5*100 = 700 how do i pass the result to a label.text :doh::doh:
-
do i miss something..? i don´t get it? foreach (ListViewItem item in listview3.items) { result += item.subitem[4] * item.subitem[5]; } Label12.Text = result.ToString(); is this right??:doh:
That will iterate through all the ListViewItems in listview3's items collection. With each item it will multiple the 4th subitem with the 5th subitem and add that to the result variable. Once the loop has completed, you are assigning that result variable to the Text property of the Label control. So let's assume this ( using periods for decimal <US Standard> ):
listview3 contains:
row1: blah, blah, blah, blah, 3.5, 100
row2: blah, blah, blah, blah, 2.5, 100result = 0
First Iteration of loop: 3.5 * 100 = 350 : result = result + 350, so result is now 350
Second Iteration of loop: 2.5 * 100 = 250 : result = result + 350, so result is now 600Hope that helps explain it.
-
That will iterate through all the ListViewItems in listview3's items collection. With each item it will multiple the 4th subitem with the 5th subitem and add that to the result variable. Once the loop has completed, you are assigning that result variable to the Text property of the Label control. So let's assume this ( using periods for decimal <US Standard> ):
listview3 contains:
row1: blah, blah, blah, blah, 3.5, 100
row2: blah, blah, blah, blah, 2.5, 100result = 0
First Iteration of loop: 3.5 * 100 = 350 : result = result + 350, so result is now 350
Second Iteration of loop: 2.5 * 100 = 250 : result = result + 350, so result is now 600Hope that helps explain it.
You excplains pretty nice Chris =) int result = 0; foreach (ListViewItem lvi in listView3.Items) { result += (lvi.SubItems[4].ToString()) * (lvi.SubItems[5].ToString()); } label12.Text = result.ToString(); it says: Error1Operator '*' cannot be applied to operands of type 'string' and 'string' can´t i use * in that order? What do should i do??:sigh::sigh: -- modified at 19:56 Friday 7th September, 2007
-
You excplains pretty nice Chris =) int result = 0; foreach (ListViewItem lvi in listView3.Items) { result += (lvi.SubItems[4].ToString()) * (lvi.SubItems[5].ToString()); } label12.Text = result.ToString(); it says: Error1Operator '*' cannot be applied to operands of type 'string' and 'string' can´t i use * in that order? What do should i do??:sigh::sigh: -- modified at 19:56 Friday 7th September, 2007
result += (float)(lvi.SubItems[4].Text) * (float)(lvi.SubItems[5].Text); And also note that result should now be a float, not an int. I didn't even consider that you were using "," as the decimal separator. I am so used to using ".", that I didn't even consider the alternative. Sorry for the confusion. -Jeff