wBB
wBB

Reputation: 851

How to access an ItemAppearance from ListView in Delphi 10?

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?

enter image description here

Upvotes: 2

Views: 2422

Answers (2)

skyzoframe
skyzoframe

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

wBB
wBB

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

Related Questions