So ähnlich könnte man es wohl machen:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
loop : integer;
ItemRect: TRect;
MaxWidth, MaxHeight : integer;
begin
MaxWidth := 0;
MaxHeight := 0;
for loop := 0 to pred(ListView1.Items.Count) do
begin
ItemRect := ListView1.Items.Item[loop].DisplayRect(drBounds);
if ItemRect.Right > MaxWidth then
MaxWidth := ItemRect.Right;
if ItemRect.Bottom > MaxHeight then
MaxHeight := ItemRect.Bottom;
end;
inc(MaxWidth, 4);//wegen Scrollbar
inc(MaxHeight, 4);
//Form anpassen
Listview1.Parent.Width := Listview1.Parent.Width - Listview1.ClientWidth + MaxWidth;
Listview1.Parent.Height := Listview1.Parent.Height - Listview1.ClientHeight + MaxHeight;
//Listview Abmessung anpassen
Listview1.ClientWidth := MaxWidth;
Listview1.ClientHeight := MaxHeight;
end;