I have a list view control on one of my forms in my program.
If i click on a selected item and click on the delete button it gets removed. But i want it so that if i havent got an item selected i click on delete i get a message box telling the user to select an item to delete. i cant seem to get that to happen.
What code would i need?
thanks

Try putting this in your button click event:

If ListBox1.SelectedIndex = -1 Then 
            MsgBox("Please select an object to delete.")
        Else
            ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
        End If

Its a listview not a listbox

Nevermind. its done
thanks

Sorry, I misread.

its ok
thanks again

for removing the item from the listview you can use

For Each lvItem As ListViewItem In lstmat.SelectedItems
            lvItem.Remove()
Next

''lstmat is listview 's name
try this one it works

thanx pritesh2010:-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.