0
votes

I have a TListView and when the user clicks on the image of an item (big green dot in picture below) i want to copy the item text ("russtest.cfg") and subitem text ("My Device, 1991") to display in a ShowMessage. I can't find how to do it in C++ Builder but this link shows how in Delphi.

enter image description here

Below is the code i've tried in the TListView's ItemClickEx method:

  TListItem* item;
  item = ListView1->Items->Item[ItemIndex];
  UnicodeString s;
  s = item->ToString();
  ShowMessage(s);

But it brings back this:

enter image description here

EDIT 1: Added the code i use to populate the ListView:

    TListViewItem* item2Add = Form1->ListView1->Items->Add();
    Form1->ListView1->BeginUpdate();
    item2Add->Text = mystring3;     // e.g. "russtest.cfg"
    item2Add->Detail = mystring2;   // e.g. "My Device, 1991"
    item2Add->ImageIndex = 1;  // big green dot
    Form1->ListView1->EndUpdate();
1
Try item->Text and item->Detail. Btw. the Delphi link is concerning a VCL TListView, not FMX. - Tom Brunberg
If my previous comment did not help, then please show how the item (including all aspects) is originally made. - Tom Brunberg
Hi Tom - when i changed to item->Text i get an error 'Text is not a member of TListItem'. I'll add an EDIT 1 to my post to show how i populate the ListView in the first place. Thank you. - relayman357

1 Answers

2
votes

Your need to typecast the TListItem* to TListViewItem*, then you can access its Text property:

TListViewItem* item = static_cast<TListViewItem*>(ListView1->Items->Item[ItemIndex]);
String s = item->Text;
ShowMessage(s);