delphifiremonkeytlistview

Delphi FMX TListViewItem to set Visible:=false


I fill programmatically DinamycAppearance TListview. There I have a TextButton, which sometimes I want to set Visible:=false.

li := ListView.Items.Add;

I tried these solutions, but neither works correctly:

li.Objects.ObjectByName('ButtonSelect').Visible := false;
li.View.FindDrawable('ButtonSelect').Visible := false;

I also tried to Destroy or Free this Object, but there I got errors.

Additionally sometimes it works, but just on the second buildup, but when I resize the Form, the ListView also forgets the visibility setup.

Do you have working solutions for this problem?

Thank you!


Solution

  • When using a Dynamic Listview item and you want to change the appearance of objects inside the items you need to do it under the OnUpdateObjects event of the listview.

    Like so:

    procedure TForm2.lv1UpdateObjects(const Sender: TObject;
      const AItem: TListViewItem);
    begin
      if SomeCondition then // SomeCondition is an example
        AItem.Objects.FindObjectT<TListItemTextButton>('ButtonSelect').Visible := False;
    end;