1.11M Members

Updates Item in ListView

 
0
 

Hello Guys Help Me To Count The Item in Listview and Update it.
Scenario..
Customer Buy 3 Milk and 2 Nescafe then the Cashier Punch it
Item-----------------Qty
Milk-------------------2
Nescafe---------------2

The Cashier Forget to Punch the 1 Milk. the Cashier should Punch Another One Milk..But My Code This is What Happen

Item---------------Qty
Milk-----------------3
Nescafe-------------2

Then I want to become like this
Item---------------Qty
Milk-----------------2
Nescafe-------------2
Milk-----------------1

in First row It is Milk then 2nd Row is Nescafe then Third tow in Milk Again..
The Qty, Of Milk Doesn't Updated Because Nescafe Insert Between Them,

If Nescafe Doesn't Inserted Between them The Qty Become 3/..

Just Like What i Mean Sir..

What Should I do ?

Many Thanks Sir

this is my code

Dim Itm  As MSComctlLib.ListItem
Dim X    As Double
Dim Dbl1 As Double
Dim Dbl2 As Double
Dim Aux1 As String
    Aux1 = ""
    For X = 1 To ListView1.ListItems.Count
      If ListView1.ListItems(X).Text = txtCode.Text Then
        'Qty
        Dbl1 = CDbl(ListView1.ListItems(X).SubItems(2))
        Dbl2 = CDbl(txtqty.Text)
        ListView1.ListItems(X).SubItems(2) = Format((Dbl1 + Dbl2))
        'Total
        Dbl1 = CDbl(ListView1.ListItems(X).SubItems(4))
        Dbl2 = CDbl(lbltotal.Text)
        ListView1.ListItems(X).SubItems(4) = Format((Dbl1 + Dbl2), "###################.00")
        Aux1 = "*"
      End If
    Next X

    If Aux1 = "" Then
      Set Itm = ListView1.ListItems.Add(, , txtCode.Text)
          Itm.SubItems(1) = txtproductname.Text
          Itm.SubItems(2) = txtqty.Text
          Itm.SubItems(3) = txtprice.Text
          Itm.SubItems(4) = lbltotal.Text
    End If
 
0
 

Something like this should work:

    Dim Itm As MSComctlLib.ListItem
    Dim X As Double
    Dim Dbl1 As Double
    Dim Dbl2 As Double
    Set Itm = ListView1.FindItem(txtCode.Text,0)
    If Itm Is Nothing Then
        Set Itm = ListView1.ListItems.Add(, , txtCode.Text)
        Itm.SubItems(1) = txtproductname.Text
        Itm.SubItems(2) = txtqty.Text
        Itm.SubItems(3) = txtprice.Text
        Itm.SubItems(4) = lbltotal.Text
    Else
        'Qty
        Dbl1 = CDbl(Itm.SubItems(2))
        Dbl2 = CDbl(txtqty.Text)
        Itm.SubItems(2) = Format((Dbl1 + Dbl2))
        'Total
        Dbl1 = CDbl(Itm.SubItems(4))
        Dbl2 = CDbl(lbltotal.Text)
        Itm.SubItems(4) = Format((Dbl1 + Dbl2), "###################.00")
    End If
 
0
 

Same Output in My Code.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article