Selecting other listview item after removing one

  • Thread starter Thread starter Bart Steur
  • Start date Start date
B

Bart Steur

Hi,

What's the best way to programmaticly select (click) another listview Item
after removing the selected/focused one.

using VB2005 Express.

Thanks
Bart
 
Typically...
- Get the index of the selected item and store in a local integer.
- The remove the selected item
- Now check to see that the selected item's index is less than the max index
(list count -1). (I.E. did you just remove the last item in the menu)
- If the index is still valid, select this item otherwise select the last
item in the list.
 
I would do it on the "SelectedIndexChanged" event.
In Visual Studio, if you click on the list, then in the properties window,
click on the little lightening bolt, this shows you what events you
currently have configured. To create one, find the event and double click on
it. This will create a new event in the code.

Alternatively, to do it manually. In the constructor of the form, you can
reference the list promatically (provided it's already been created) and
find the event in there and specify a target event handler method to handle
that event.

Hope that helps.
 
I don't think I understand your solution.

I'm used to VB6 (For almost a decade). There you had the ItemClick Event
which supplied the Item that was clicked. Now online help suggests to use
the Click event in combination with Listview.FocusItem.
So I used that. Clicking an Item loads an image into a picturebox.
So to delete one I use Listview.FocusedItem.Remove. Now after deleting I
want to programmaticly click the preceding item in the list. So the
Click_event coding is triggered and the image is shown.

Thanks
Bart
 
Bart,

You want to select an item and have it display the picture in the listview,
which I believe you have at the moment?
Now you want to remove this item (presumably with some delete button press)
and have another item selected, and in doing so have the picture for that
list item displayed?
What version of Visual Studio are you using?

If this is not what you are doing, please first describe this, then maybe
we'll be able to help.

Thanks.
Daniel.
 
Back
Top