how to set visible true or false on TextButton in listview

77 Views Asked by At

I'm using Delphi 10.4 Community Edition.

I have 3 items in a ListView with dynamic appearance, and 1 DateEdit:

  • 2 textButtons, with name btnCheck and btnUnchek
  • 1 textItem, with name txtSteam. This item has a value of 1 or 0
  • the DateEdit with name edtTanggal

I want that when txtSteam = 1 then btnCheck.Visible = false and btnUncheck.Visible = true. But I want to execute this logic in the OnChange event of edtTanggal.

I've managed to display the desired data in the ListView, but I can't control the visibility of the textButtons.

1

There are 1 best solutions below

0
SergeGirard On

You have to use UpdateObjects event of Listview

procedure TForm1.ListView1UpdateObjects(const Sender: TObject; 
const AItem: TListViewItem);
begin
 if AItem.Purpose<>TListItemPurpose.None then  exit;
 var v:= AItem.Objects.FindObjectT<TListItemText>('txtSteam');
 var btn1:= AItem.Objects.FindObjectT<TListItemTextButton>('btnCheck');
 if Assigned(btnCheck) then
   btncheck.Visible:=v.text<>'1';

 var btn2:= AItem.Objects.FindObjectT<TListItemTextButton>('btnUncheck');
 if Assigned(btn2) then
    btn2.Visible:=v.text='1';
end;