Search code examples
delphilazarus

Add Value to Column TShellListview


I have a TShellListView in Lazarus with some Pictures in it. I also made 2 column where I want to store some data About the Picture. But I don't know how to insert the data into the columns I made (Column_1 and Column_2).

Code:

ShelLListView1.Column[1].Visible:=false;
 ShelLListView1.Column[2].Visible:=false;

 ShellListView1.Columns.Add;
 ShellListView1.Column[ShellListView1.ColumnCount - 1].Caption:='Column_1';
 ShellListView1.Columns.Add;
 ShellListView1.Column[ShellListView1.ColumnCount - 1].Caption:='Column_2';


 ShelLListView1.Column[0].AutoSize:=true;
 ShellListView1.Root:=folderPath;

Image About the TShellListView:

enter image description here


Solution

  • Even though making a subclass of the TShellListView class would be better, what you need in any case is adding subitems to this list view:

    var
      I: Integer;
    begin
      ...
      for I := 0 to ShellListView1.Items.Count - 1 do
      begin
        ShellListView1.Items[I].SubItems.Add('Column 1, Item: ' + IntToStr(I));
        ShellListView1.Items[I].SubItems.Add('Column 2, Item: ' + IntToStr(I));
      end;
    end;