Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listview 1

Status
Not open for further replies.

GAORR

Programmer
Nov 22, 2001
48
CA
After removing an item from a listview, I would like to select (hilite) the first (or any other) item that remains in the listview. Can anyone help with the syntax.

 
I have found the answer, which I have included for others.

lvListView.SetFocus
lvListView.ListItems(i).Selected = True

 
Which, of course, won't work if you've just removed the ith item of i items! (As I've found to my cost)

I would suggest checking the index of the item you've just deleted against the count of items, and if higher set to count:
Code:
i = lvListView.SelectedItem.Index
lvListView.ListItems.Remove i
If i > lvListView.ListItems.Count Then i = lvListView.ListItems.Count
lvListView.ListItems(i).Selected = True

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top