hello Guys,, I am Developing POS and I have A Code To Add An item into Listview Then Exactly Work.. Then My Problem is, what if the Customer Select two Similar Item let Say 3 Pack of Milk and 2 Sardines..
Example:
Item--------------QTy
Milk--------------- 1
Sardines---------- 2
I forgot to add 2 pack of milk, Then I want to become like this
Example:
Item--------------QTy
Milk--------------- 1
Sardines---------- 2
Milk--------------- 2..
But in My code this is What happen
Item--------------QTy
Milk--------------- 3
Sardines---------- 2
Its Updated the QTy Instead Make A another Row.
HElo Guys,, This is My code..
Code:
Dim qtyadd As String
Dim subtotaladd As String
Dim itm As MSComctlLib.ListItem
Dim i As Integer
Set itm = ListView1.FindItem(txtCode.Text)
If Not itm Is Nothing Then
itm.EnsureVisible
itm.Selected = True
qtyadd = Val(txtqty.Text) + Val(ListView1.SelectedItem.SubItems(2))
subtotaladd = Val(lbltotal.Text) + Val(ListView1.SelectedItem.SubItems(4))
ListView1.SelectedItem.SubItems(2) = qtyadd
ListView1.SelectedItem.SubItems(4) = Format(subtotaladd, "###################.00")
Else
ListView1.ListItems.Add , , txtCode.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtproductname.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtqty.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtprice.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , lbltotal.Text
End If
If you want to just add to listview control every scanned item, then replace all your posted code by the next:
Code:
Dim itm As MSComctlLib.ListItem
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
This is what i mean if the Item is already in Listview Then there are two items in Listview like
Item--------------QTy
Milk--------------- 1
Sardines---------- 2
Then The Customer Decide a Buy Another Milk then it should be like this
Item--------------QTy
Milk--------------- 1
Sardines---------- 2
Milk--------------- 1
Then My Problem is If The Customer Buy Another Milk then Code Run it should be like this
Item--------------QTy
Milk--------------- 2
Sardines---------- 2
not this one..
Item--------------QTy
Milk--------------- 1
Sardines---------- 2
Milk--------------- 1
Dim Itm As MSComctlLib.ListItem
Dim X As Integer
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.Caption)
ListView1.ListItems(X).SubItems(4) = Format((Dbl1 + Dbl2))
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.Caption
End If
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
Dim Itm As MSComctlLib.ListItem
Dim X As Integer
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.Caption)
ListView1.ListItems(X).SubItems(4) = Format((Dbl1 + Dbl2))
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.Caption
End If
Hello Sir,,
Sorry for My Mistake,,
This is what i mean if the Item is already in Listview Then there are two items in Listview like
Item--------------QTy
Milk--------------- 1
Sardines---------- 2
Then The Customer Decide a Buy Another Milk then it should be like this
Item--------------QTy
Milk--------------- 1
Sardines---------- 2
Milk--------------- 1
Then My Problem is If The Customer Buy Another Milk then Code Run it should be like this
Item--------------QTy
Milk--------------- 1
Sardines---------- 2
Milk--------------- 1
not this one..
This a small listview example
Let's start with it
Study it
Modify it...
add textboxes Qty, Description, Price & Total
add columns to listview
Repost when done
Say your Country
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
Dim Dbl1 As Double
Dim Dbl2 As Double
Dim Aux1 As String
Dim qtyadd As String
Dim subtotaladd As String
Dim itm As MSComctlLib.ListItem
Dim i As Integer
Set itm = ListView1.FindItem(txtCode.Text)
If itm Is Nothing Then
ListView1.ListItems.Add , , txtCode.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtproductname.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtqty.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtprice.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , lbltotal.Text
ElseIf ListView1.ListItems.Item(ListView1.ListItems.Count).Text <> txtCode.Text Then
ListView1.ListItems.Add , , txtCode.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtproductname.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtqty.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtprice.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , lbltotal.Text
ElseIf Not itm Is Nothing Then
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i).Text = txtCode.Text Then
Dbl1 = (ListView1.ListItems(i).SubItems(2))
Dbl2 = (txtqty.Text)
ListView1.ListItems(i).SubItems(2) = Format((Dbl1 + Dbl2))
'Total
Dbl1 = (ListView1.ListItems(i).SubItems(4))
Dbl2 = (lbltotal.Text)
ListView1.ListItems(i).SubItems(4) = Format((Dbl1 + Dbl2), "###################.00")
Aux1 = "*"
End If
Next i
End If
So if you have.
item1 1
then add item1 again you get
item1 2
also if you have
item2 1
item1 1
and then you add item1 you get
item2 1
item1 2
but, if you have
item1 1
item2 1
then you add another item1, you want
item1 1
item2 1
item1 1
in my code the Output is
All Item 1 Added by 1
like then you add another item1, you want
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.