Search code examples
vclborland-c++

How to set an image for a subitem in a listview in a runtime?


The question is similar to existing one for .NET and C# but I think in Borland C++ should be another way to do this.

In the edit time I can easily set image for subitem in listview as well as for item (in Object Inspector's special Items editor). But in runtime I cannot do this because I have no reference on subitem.

ListView2->ViewStyle = vsReport;
ListView2->SmallImages = ImageList1;
TListColumn* column;
column = ListView2->Columns->Add();
column->Caption = "col1";
column = ListView2->Columns->Add();
column->Caption = "col2";

TListItem* item = ListView2->Items->Add();
item->Caption = "Item";
item->ImageIndex = 2;
item->SubItems->Add("Subitem");

Is there any way to get reference to the new Subitem?


Solution

  • I found out that decision is a very simple one. There's a property to get/set image number for sub items:

    item->SubItemImages[0] = 3;
    

    By the way it's a pretty nice method to have 2 or even more pictogram for each listview item.