TListView - How to rearrange items on resize

delphi, listview

Solution

There is a property like `AutoArrange`. It belongs to the `IconOptions` property instead of directly to the list view.

ListView1.IconOptions.AutoArrange := True;

To make a one-time arrangement of the icons, you can call `ListView_Arrange` instead.

Problem

I have a TListView that displays small thumbnails `(ViewStyle:=vsIcon)`. At run time I assign images to to items: ``` for i := 0 to Total - 1 DO with ListView.Items.Add DO begin Caption := 'Item ' + IntToStr(i); ImageIndex := i; end; ``` At start up the form is not very wide and the thumbnails are shown on only 3 columns. Unfortunately, If I resize the form (and the ListView) the column count will remain 3 and in the right side I will have a lot of white space. This won't work also: ``` procedure TForm1.FormCreate(Sender: TObject); begin ListView.IconOptions.AutoArrange := TRUE; end; ``` How do I rearrange the items to fill the empty space? There is any property like AutoArrange? Update: I deleted the old control and I put a new one on the form. Now `ListView.IconOptions.AutoArrange` works. There was something (some settings I made) in the previous control that prevented AutoArrange from working.

Original source