2004. március 19., péntek

Change the position of a list item in a TListView (4)


Problem/Question/Abstract:

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:

procedure ScrollItemtoTop(lv: TLIstview; index: Integer);
var
  num: Integer;
  scrollcode: Integer;
begin
  num := lv.TopItem.Index - index;
  if num < 0 then
  begin
    scrollcode := SB_LINEDOWN;
    num := Abs(num);
  end
  else
    scrollcode := SB_LINEUP;
  lv.Items.BeginUpdate;
  try
    while num > 0 do
    begin
      lv.Perform(WM_VSCROLL, scrollcode, 0);
      Dec(num);
    end;
    lv.Perform(WM_VSCROLL, SB_ENDSCROLL, 0);
  finally
    lv.Items.EndUpdate;
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése