delphifiremonkeyfiredaclivebindingstlistview

How to get the values of TListView selected item in Firemonkey Delphi Rio


I have a TListView populated with data from TFDQuery using Livebindings.

I would like to get the values of the selected item like the item.text, itemheader.text, etc. I already figured out the selected item through listview1.itemindex but to get the values is a struggle to me. I am new with TListView and livebindings. I've spent over a day already looking for answers in the internet but looks too complicated for a very simple task. I know there is a straight method for this.

Anyone care to share some clues (codes) on how to get the values of listview selected item?

MORE DETAILS:

I am using the Livebindings dynamic appearance. I created items for my query fields and map them accordingly to my TListView.

It so happen that I did not use the default item.text but instead map fields to my created items like item.text1, item.text2, item.item3.

Hence, this is the reason why I am not getting the caption from the formula given by MartynA below.


Solution

  • Perhaps I am missing your point (in which case I'll delete this) but the following FMXcode works fine for me:

    procedure TForm1.Button2Click(Sender: TObject);
    var
      Index : Integer;
    begin
      Index := ListView1.ItemIndex;
      if Index >= 0 then
        Caption := ListView1.Items[Index].Text;
    //  OR  ShowMessage(ListView1.Items[Index].Text);
    //  OR  Label1.Text := ListView1.Items[Index].Text;
    
    end;