Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TcxCustomListView.OnGetSubItemImage Event

In This Article

Occurs when it is required to determine image associated with a sub-item.

#Declaration

Delphi
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.

See Also