Question Deleting File in Listview and Listbox by name (FileName/SafeFileName)

jdkoops

Member
Joined
Sep 5, 2008
Messages
17
Programming Experience
Beginner
Hi Friends,

I have two controls - listview and listbox. The listview has the safeFileName and the listbox the fileName.

with the listview i have the option to deleted a line item (removeAt) but i need the listbox to update and delete whatever is selected/deleted as well.

Can someone please help with the code?

Thanks,
J
 
Thanks for quick answer. Can you please review this; it's not working:


For i As Integer = ListView1.Items.Count - 1 To 0 Step -1
If ListView1.Items(i).Selected Then ListView1.Items.RemoveAt(i)

Next

ListBox2.Items.RemoveAt(i)

Thank-you,
J
 
Think about what that code is doing. It's looping through all the items in the ListView and removing all the ones that are selected and then, when that's all done, it tries to remove one item from the ListBox. Does that make sense? That is always going to try to remove one item from the ListBox, whether there are zero, one or more items selected in the ListView. Obviously that's not right. Think about what it is that you need to achieve first. Pick up a pen and paper and write down if you need to. Then, when you write the code, you can look at it and ask yourself whether the code matches the logic. If it doesn't then it's obvious why the code doesn't work. If it does match and still doesn;t work then there's an issue with your logic.
 
This seems to be working:

Dim index As Integer = ListView1.SelectedIndices(0)
ListBox2.Items.RemoveAt(index)
ListView1.Items.RemoveAt(index)

Thanks; your advice worked (the 1st one lol) ..
 
Back
Top