Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
0 down vote
favorite
i am making a pos software and now my clients request is when they add 1 items 2 times in listbox so it's just show one time but quantity of this item increase i am working on this but i dont know how to work on quantity.
C#
Button b = (Button)sender;
tblProduct tp = (tblProduct)b.Tag;
string product = tp.productName;
lbProductsToBuy.Text = tp.ToString();
products.Add(tp);
total += (decimal)tp.productPrice;
var duplicates = products.GroupBy(i => i.productName)
                 .Where(x => x.Count() > 0)
                 .Select(val => val.Key);

 foreach (var item in duplicates)
 {

 }
and listbox format is

   try
            {
                string ProductName = ((tblProduct)e.ListItem).productName;
                string Price = "Rs: " + String.Format("{0:}", ((tblProduct)e.ListItem).productPrice);
                string ProductNamePadded = ProductName.PadRight(33);
                e.Value = ProductNamePadded+Price;
            }
            catch
            {
            }

look at this image of issue
\http://imgur.com/a/1DhiV

What I have tried:

0
down vote
favorite
i am making a pos software and now my clients request is when they add 1 items 2 times in listbox so it's just show one time but quantity of this item increase i am working on this but i dont know how to work on quantity.

C#
Button b = (Button)sender;
tblProduct tp = (tblProduct)b.Tag;
string product = tp.productName;
lbProductsToBuy.Text = tp.ToString();
products.Add(tp);
total += (decimal)tp.productPrice;
var duplicates = products.GroupBy(i => i.productName)
                 .Where(x => x.Count() > 0)
                 .Select(val => val.Key);

 foreach (var item in duplicates)
 {

 }
and listbox format is

   try
            {
                string ProductName = ((tblProduct)e.ListItem).productName;
                string Price = "Rs: " + String.Format("{0:}", ((tblProduct)e.ListItem).productPrice);
                string ProductNamePadded = ProductName.PadRight(33);
                e.Value = ProductNamePadded+Price;
            }
            catch
            {
            }
Posted
Updated 7-Aug-16 16:59pm
v2

1 solution

C#
duplicates.Select(c => { c.value = txtbox.Text; return c; }).ToList()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900