Link to home
Start Free TrialLog in
Avatar of boardtc
boardtcFlag for Ireland

asked on

TListView virtual mode & Selected

I have a TListView in virtual mode. I set the Selected property to an item outside the current listbox. If U scroll down the list I can see the new item selected ?_but_ how can I get the list box to automatically move it's view on the TCollection down to include the new selected (via code) item.

Thanks, Tom.
Avatar of DragonSlayer
DragonSlayer
Flag of Malaysia image

try something like this?

ListView1.Items[myIndex].MakeVisible(False);

or

ListView1.TopItem := ListView1.Items[myIndex];
Avatar of Madshi
Madshi

I'm not sure whether the "Items" property works completely, when using virtual mode. I'm using the following function when doing virtual mode:

ListView_EnsureVisible

Regards, Madshi.
Hmm... yeah, forgot about that.

Didn't try it myself, but you just *might* get a List Index Out of Bounds error.

So Tom, Madshi is correct, just follow his suggestion and call it this way:

ListView_EnsureVisible(ListView1.Handle, myIndex, False);

and don't forget to add CommCtrl in your uses clause.

(PS: If this works, give the points to Madshi)
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of boardtc

ASKER

It turns out that
ListView1.Items[myIndex].MakeVisible(False);
is a wrap for
ListView_EnsureVisible(ListView1.Handle, myIndex, False);
so both work perfectly :-)
There doesn't seem to be any advantage to using the later.

FYI, ListView1.TopItem is readonly.

The selected index however shows at the bottom of the TListView and I want it toward the top. I want to do

ListView1.Items[myIndex+NumberItemsVisibleInList].MakeVisible(False);

Do ye have any idea how I can get
the number of items visible in the list?

Thanks a million, Tom.
ListView_GetCountPerPage
Avatar of boardtc

ASKER

Thanks for you guys help. Great, Tom.