Scrolling & TListView

Please discuss general Delphi programming topics here.

Scrolling & TListView

Postby Johnny_Bit » July 22nd, 2003, 4:52 pm

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.
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby Kambiz » July 27th, 2003, 3:21 pm

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby Johnny_Bit » July 27th, 2003, 4:05 pm

Thanks Kamibiz, it was it. Ind to think i want to do it by those messages that you mentioned
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 13 guests

cron