Page 1 of 1

Scrolling & TListView

PostPosted: July 22nd, 2003, 4:52 pm
by Johnny_Bit
I've got a few questions:

1. How to get scroll position of both scrollbars in TListView?
2. How to set scroll position of both scrollbars in TListView?
3. How to scroll to specified item?
3a. How to scroll to item with Item.Data=specified pointer?

Thanks in advance.

PostPosted: July 27th, 2003, 3:21 pm
by Kambiz
To get the scroll bars position of any window you can use the following code:

Code: Select all
HorzPos := GetScrollPos(WindowHandle, SB_HORZ);
VertPos := GetScrollPos(WindowHandle, SB_VERT);

For most of windows, you can use the following code to set the scroll bars position:

Code: Select all
 SendMessage(WindowHandle, WM_HSCROLL, MakeLong(SB_THUMBPOSITION, HorzPos), 0);
SendMessage(WindowHandle, WM_VSCROLL, MakeLong(SB_THUMBPOSITION, VertPos), 0);

However, the above code does not work for TListView. :(

To scroll to a specified item of a ListView you can use MakeVisible method of the TListItem as follow:

Code: Select all
Item.MakeVisible(False);

TListView does not have a built-in function to locate an item with a specific data member. So, you have to find the item yourself.

Code: Select all
for I := ListView.Items.Count - 1 downto 0 do
  with ListView.Items[I] do
    if Data = MyData then
    begin
      MakeVisible(False);
      Break;
    end;

Hope I could be helpful.

Cheers,
Kambiz

PostPosted: July 27th, 2003, 4:05 pm
by Johnny_Bit
Thanks Kamibiz, it was it. Ind to think i want to do it by those messages that you mentioned