Author: Tomas Rutkauskas
I want to keep one row as the topmost visible row in a TListView. Each time it will
vary according to my search, which one I found I want to make that one as a topmost
row. How can I do this?
Answer:
Scroll a listview item to the top:
1 procedure ScrollItemtoTop(lv: TLIstview; index: Integer);
2 var3 num: Integer;
4 scrollcode: Integer;
5 begin6 num := lv.TopItem.Index - index;
7 if num < 0 then8 begin9 scrollcode := SB_LINEDOWN;
10 num := Abs(num);
11 end12 else13 scrollcode := SB_LINEUP;
14 lv.Items.BeginUpdate;
15 try16 while num > 0 do17 begin18 lv.Perform(WM_VSCROLL, scrollcode, 0);
19 Dec(num);
20 end;
21 lv.Perform(WM_VSCROLL, SB_ENDSCROLL, 0);
22 finally23 lv.Items.EndUpdate;
24 end;
25 end;