Listview Question

Hello, i am in need of some help working with a listview in VB.

I need to be able to add to a QTY within the list view... This is my code right now:

Private Sub Form_Load()
With LV1
        .ColumnHeaders.Add , , "QTY", 550
        .ColumnHeaders.Add , , "Item Name", 2500
        .ColumnHeaders.Add , , "Price"
        .View = lvwReport
End With
End Sub

Private Sub Command3_Click()
Dim ListObj As ListItem
Dim QTY, Name As String
Dim Price As String

Name = "Sandwich"
QTY = "1"
Price = "$" & "1.22"
        Set ListObj = LV1.ListItems.Add(, , QTY)
        ListObj.SubItems(1) = Name
        ListObj.SubItems(2) = Price
End Sub

This is what it looks like when i push the command button to test it out..
QTY  |   Item      |   Price
 1       Sandwich    $1.22
 1       Sandwich    $1.22

But i need it to do this...

QTY  |   Item      |   Price
 2       Sandwich    $2.44

So this is what i need:
 - The QTY to add if the button is hit more than just once
 - Add the Price if the button is hit more than just once

Thats it!

Thanks for your time,
David
StealthrtAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DabasCommented:
Hi Stealthrt:
Does your listview have to be Qty Item Price, or can it be Item Qty Price
Reason I am asking is that you probably will need to use the ListView's FindItem function, and it will be easier if your ListItem's text property is the one to search

Dabas
0
StealthrtAuthor Commented:
I would like it to be first so it could be read as 1 item price.... But if it wont work like that then i guess i could have it as item qty price.... But i really would like it more qty item price...

David
0
DabasCommented:
David:
Its not a big issue.
instead of Set ListObj = lv1.listitems.add(,,Qty)
Try

    Set ListObj = lv1.FindItem(Name, lvwSubItem)
    If ListObj is nothing then
        Set ListOBj = lv1.ListItems.Add(,,Qty)
    else
        listObj.Text = Val(ListObj.Text) + Qty)
    end if

    ListObj.SubItems(1) = Name
    ListObj.Subitems(2) = Price
Dabas
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StealthrtAuthor Commented:
That worked just fine Dabas...

Another question though... if i wanted to double click on that in the listview to subtract one from the quanity, how would i do that? Im able to do that now but only if its the same product.

Private Sub LV1_DblClick()
Dim ListObj As ListItem 'Set listObj as a listitem
Dim QTY, Name As String
Dim Price As String

Name = "CFA Sandwich"
Price = "$" & "1.22"
QTY = 1
Set ListObj = LV1.findItem(Name, lvwSubItem)
    If ListObj Is Nothing Then
        Set ListObj = LV1.ListItems.Add(, , QTY)
    Else
        ListObj.Text = Val(ListObj.Text - QTY)
    End If

    ListObj.SubItems(1) = Name
    ListObj.SubItems(2) = Price

End Sub

Any suggestions?

Thanks again,
David
0
DabasCommented:
Stealthrt:
>         ListObj.Text = Val(ListObj.Text - QTY)
Should be Val(ListObj.Text) - QTY

Dabas
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.