TcxCustomListView.OnGetSubItemImage Event
Occurs when it is required to determine image associated with a sub-item.
Declaration
property OnGetSubItemImage: TLVSubItemImageEvent read; write;
Remarks
Handle the OnGetSubImageIndex event if you wish to take some specific action when the TcxListView control attempts to retrieve the index of the image, which is associated with a sub-item. Images that can be associated with the list view sub-items are stored in the SmallImages image list. To assign an image to the sub-item, use the SubItemImages property of a TListItem instance, representing a list view item. The following code demonstrates assigning sub-item images by handling the TForm.OnCreate event:
procedure TForm1.FormCreate(Sender: TObject);
const
Names: array[0..5, 0..1] of string = (
('Rubble', 'Barney'),
('Michael', 'Johnson'),
('Bunny', 'Bugs'),
('Silver', 'HiHo'),
('Simpson', 'Bart'),
('Squirrel', 'Rocky')
);
var
I: Integer;
ListItem: TListItem;
begin
for I := Low(Names) to High(Names) do
begin
ListItem := cxListView1.Items.Add;
ListItem.Caption := Names[I][0];
ListItem.SubItems.Add(Names[I][1]);
ListItem.SubItemImages[0] := High(Names) - I;
ListItem.ImageIndex := I;
ListItem.StateIndex := 1;
end;
end;
The result is demonstrated on the following screenshot:
By handling the OnGetImageIndex property you can dynamically associated images with specific sub-items.
Sender specifies the TcxCustomInnerListView.
Item specifies the item, whose sub-item’s image index is requested.
SubItem represents the index of the required sub-item within the Item.SubItems collection.
Pass the image index as the ImageIndex parameter.