Enable/disable button when Listview accessory type is visible/not visible

  

I have a form with a firemonkey listview on it. This listview contains multiple items in it.

Using OnItemClick procedure I am trying to make a button enabled when the listview accessory type(Checkmark) is visible for each item and disabled when the accessory is not visible on all items.

I have the following code to make the accessory visible on each item when clicked.

Tform.ListView1ItemClick(const Sender: TObject; const AItem: TListViewItem);
begin
if AItem.Objects.AccessoryObject.Visible then
begin
AItem.Objects.AccessoryObject.Visible := False;
end
else
begin
AItem.Objects.AccessoryObject.Visible := True;
end;
end;

I then added the following thinking it would give me what I’m after.

for i := 0 to AItem.Count -1 do
begin
if (AItem.Objects.AccessoryObject.Visible) then
begin
Button1.Enabled := True
end else Button1.Enabled := False;

For every item clicked in the listview the accessory will be visible, clicking the item again will hide the accessory. So if the accessory is visible on 1 item or more then the button will be enabled, if the accessory is removed on all items then the button should be disabled.

Comments are closed.