Reputation: 851
As shown in this image below, I need to select the value of the txtID
field when clicking on the item in the ListView. How do I do that?
Upvotes: 2
Views: 2422
Reputation: 11
{$R *.fmx}
procedure Form1.ListView1Change(Sender: TObject);
begin
if ListView1.Selected <> nil
then Label2.Text := TAppearanceListViewItem(ListView1.Selected).Objects.FindObjectT<TListItemText>('txtID').Text
else Label2.Text := '-';
//If you change the selected item with keyboard (up, down, left, right), then you will get back the selected value, without clicking on it.
end;
Upvotes: 1
Reputation: 851
procedure TForm1.ListView1ItemClick(const Sender: TObject;
const AItem: TListViewItem);
begin
showmessage(AItem.Objects[1].Data.AsString); // Value of field
showmessage(AItem.Objects[1].Name); // Name of field
// OR
showmessage(AItem.Data['txtID'].AsString); // Value of field
end;
Upvotes: 4