Hallo Alois,
du kannst dir das oberste angezeigte Item (TopItem) merken und später wieder dorthin scrollen. Hier das Prinzip:
Delphi-Quellcode:
type
TDemoForm = class(TForm)
ListView: TListView;
SaveButton: TButton;
ReposButton: TButton;
procedure FormCreate(Sender: TObject);
procedure SaveButtonClick(Sender: TObject);
procedure ReposButtonClick(Sender: TObject);
private
topIndex: Integer;
end;
var
DemoForm: TDemoForm;
implementation
{$R *.dfm}
function RandomStr(size: Integer): string;
var
i: Integer;
begin
SetLength(Result, size);
for i := 1 to Length(Result) do
Result[i] := Chr(Ord('A') + Random(26));
end;
procedure TDemoForm.FormCreate(Sender: TObject);
begin
with ListView.Items do
while Count < 100 do
Add.Caption := RandomStr(5);
end;
procedure TDemoForm.SaveButtonClick(Sender: TObject);
begin
topIndex := ListView.TopItem.Index;
end;
procedure TDemoForm.ReposButtonClick(Sender: TObject);
var
itemHeight, index: Integer;
r: TRect;
begin
with ListView do
begin
index := TopItem.Index;
r := TopItem.DisplayRect(drBounds);
itemHeight := r.Bottom - r.Top;
Scroll(0, itemHeight * (topIndex - index));
end;
end;
Grüße vom marabu