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 not showing exactly what was selected

Status
Not open for further replies.

tjtindal

Programmer
Mar 22, 2004
66
US
Let's say I have a program that randomly looks through a listview to select a file to open, and then it opens it. I want the highlighted item on the listview to be what was selected but I can't seem to get the listview to move it's little scrollbars down to show the item, let alone select it.
 
Try;

with myListView
.ListItems(.SelectedItem.index).EnsureVisible
end with

HTH Hugh
 
It is now indeed doing what it is supposed to do by showing the song in the list, but is there anyway to simulate a mousehover over it so it'll light up in the "selected" way too?
 
Listviews have a property called "HoverSelection," and when you mouseover an entry in the list long enough, it will light up highlighted. Now using the above information to make it show when it selects something in the list, how can you also simulate a hover selection so it "lights up" as well as shows?
 
tjtindal,

I suggest you may be able to do that by moving the mouse 'over' an item using a Windows API call (try Googling for 'mouse move windows api' or similar).

It looks quite complicated and you may have to sub class the form; I hand it to others with more expertize.

regards Hugh
 
I think you've thrown Hugh by talking about the HoverSelection, all you really want to do is select the item in the list isn't it (which is what HoverSelection does, only on hover of the mopuse rather than clicking)?

You can do this quite easily, say you want to select the 3rd item in your listview e.g.
Code:
ListView1.ListItems(3).EnsureVisible 'scroll to the item (as per Hugh's original post)
ListView1.ListItems(3).Selected = True 'select the item
ListView1.SetFocus 'you have to setfocus back to the Listview to be able to see that you've selected it

Is this something like what you are after?

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thanks Hugh [smile]

Yeah, that allows the user to see the selected item in the 'greyed out' selection without having the control focused.

Cheers

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top