Hello
I'm doing a web shop app, and i got a chart in form iof a listView that i want to fill with items from my Listbox where all my products are.
The problem is that when i add another instance of the same item, i want the amount to increase in my list view instead of just putting it in a new row. I have 2 collumns in my listview, Name and amount.
So when i add an item that already excists in the listview i want the amount to increase in the amount column. I guess i nees some kind of for loop that compares all the name rows with the name of the marked item in my product lisbox and if it finds something, just increase the amount in the amount column... I use a numericUpDown for amounts.
Any help would be great.
Thanks alot
2 replies to this topic
#1
Posted 14 February 2011 - 05:00 AM
|
|
|
#2
Posted 14 February 2011 - 08:01 AM
In the list view you should look to see if the item already exists. If so, then increment by one, else add a new item.
If you need further help with this please post your code. :) Happy Coding.
If you need further help with this please post your code. :) Happy Coding.
-CDG10620
Software Developer
Software Developer
#3
Posted 14 February 2011 - 08:09 AM
Hi, kvarnen, welcome to CodeCall. This code should work:
Basically it use's a for loop just like you thought to loop through each item in the listView getting the text, and comparing them to the listBox selected item, then if they match change the subItem text in the listView.(in your case the subItem would be the amount)
Hope that helps, and if you have any questions just ask ~ Committed. :)
for (int i = 0; i < listView1.Items.Count; i++)
{
string text = listView1.Items[i].Text;
if (text == listBox1.SelectedItem.ToString())
{ listView1.Items[i].SubItems[1].Text = "w/e"; }
} Basically it use's a for loop just like you thought to loop through each item in the listView getting the text, and comparing them to the listBox selected item, then if they match change the subItem text in the listView.(in your case the subItem would be the amount)
Hope that helps, and if you have any questions just ask ~ Committed. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









