Subscript List Images

I missed something obvious here, I cannot find a way to assign ImageIndex to the TListView subelement.

I have a Listview set in vsReportMode with 2 columns, I can easily assign ImageIndex to the first column of Items, something like:

ListView1.Items[0].ImageIndex := 0; ListView1.Items[1].ImageIndex := 1; ListView1.Items[2].ImageIndex := 2; 

I thought I could assign ImageIndex to SubItems for it, something like this (which obviously doesn't work, because the property doesn't seem to exist with SubItems)

 ListView1.Items[0].SubItems[0].ImageIndex := 0; ListView1.Items[1].SubItems[0].ImageIndex := 1; ListView1.Items[2].SubItems[0].ImageIndex := 2; 

Am I confusing myself again or not for such a property for SubItem images?

+4
source share
1 answer

Use SubItemImages :

 var LI: TListItem; i: Integer; begin ListView1.ViewStyle := vsReport; for i := 0 to 1 do with ListView1.Columns.Add do Caption := 'Column ' + IntToStr(i); for i := 0 to ImageList1.Count - 1 do begin LI := ListView1.Items.Add; LI.Caption := Format('Item %d', [i]); LI.ImageIndex := i; LI.SubItems.Add(Format('SubItem %d', [i])); LI.SubItemImages[0] := i; // SubItems[ColumnIndex] := ImageIndex; end; end; 

The result is

ListView with SubItems and Images

+9
source

Source: https://habr.com/ru/post/1386218/


All Articles