Listview Ctrl Delete Problem

I am using the Listview ctrl in the report view and am able to delete an entry that has been selected with no problem. If I call the delete routine again without selecting an entry, the next or previous entry is deleted. How do I detect that nothing is currently selected in the Listview ctrl; i.e., I want the user to explicitly select a Listview entry for deletion. Below is the code that is currently doing the job.

strKey = lvwToppings.SelectedItem.Text
  n = MsgBox("Delete this topping?", vbYesNo, "Delete entry")
  If (n = vbYes) Then
    strRemoveKey = "L" & strKey
    lvwToppings.ListItems.Remove strRemoveKey
    n = lvwToppings.ListItems.Count
    If (n = 0 Or n = 1) Then
      curToppingCost = 0
    Else
      curToppingCost = (n - 1) * arrToppings(mintRow)
    End If
    lblToppingPrice.Caption = Format(curToppingCost, "currency")
  End If
tmbtmbAsked:
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.

tmbtmbAuthor Commented:
This code is part of a project that my second semester vb students will modify next term.

I feel that before an entry is to be deleted, my code should be able to verify (as in checking a listbox's ListIndex property = -1) to determine that an entry has been explcitly selected (or not selected).
0
manojaminCommented:
once you delete the entry,
call

lvwToppings.Refresh
0
manojaminCommented:
'do this

Private Sub DeleteThis()
    If (lvwToppings.SelectedItem.Selected) Then
        'strKey = lvwToppings.SelectedItem.Text
        n = MsgBox("Delete this topping?", vbYesNo, "Delete entry")
        If (n = vbYes) Then
            'strRemoveKey = "L" & strKey
            Call lvwToppings.ListItems.Remove(lvwToppings.SelectedItem.Index)
            'lvwToppings.ListItems.Remove strRemoveKey
            lvwToppings.Refresh
            n = lvwToppings.ListItems.Count
            If (n = 0 Or n = 1) Then
                curToppingCost = 0
            Else
                curToppingCost = (n - 1) * arrToppings(mintRow)
            End If
            lblToppingPrice.Caption = Format(curToppingCost, "currency")
        End If
    End If
End Sub
Private Sub lvwToppings_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeyDelete) Then Call DeleteThis
End Sub

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

tmbtmbAuthor Commented:
Thanks for your help. That was just what I needed.
0
tmbtmbAuthor Commented:
okay, so the questions got answered. how do you award the points?
0
manojaminCommented:
Glad that helped you... I am just entering this comment as an answer so that you can award points...

(BTW: you can alos treat the comment as an answer. Most of the time people will put comment rather than answer so that question does not get locked and people don't think that "oh! it's been answered, why bother?")
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
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.