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