如何启用或禁用具有动态外观的 TListView 中的项目?

时间:2021-01-08 12:00:14

标签: listview delphi firemonkey delphi-10.3-rio

我有一个动态外观的 TListView,有一些项目,如文本和图像。我想在运行时禁用或启用这些项目,视情况而定。

直到那一刻我才在互联网上找到参考。谢谢你的帮助..

例如:

ListView.Items.Clear;
x:=0
while not Query.eof do
begin
  Item := ListView.Items.Add;

  Listview.Items.AppearanceItem[x].Data['IdItem'] := x;
  Listview.Items.AppearanceItem[x].Data['Status'] := vStatus;
  if vStatus = 1 then   
     Listview.Items.ApperanceItm[x]....:= "enabled or disable";
  Query.next;
  x:=x+1;
end;

1 个答案:

答案 0 :(得分:0)

我认为您的意思是项目是否可见,取决于条件。

您必须使用以下代码在 OnUpdateObjects 事件处理程序中应用这些更改,例如:

procedure TForm1.ListViewUpdateObjects(const Sender: TObject;const AItem: TListViewItem);
var txt : TListItemText;
    img : TListItemImage;
begin
  txt := TListItemText(Aitem.Objects.FindDrawable('Status'));
  if txt.Text='1' then
  begin
    img := TListItemImage(AItem.Objects.FindDrawable('ImageStatus')); // ImageStatus is the name of the TImageObjectAppearance you want to show or hide
    img.Visible := false;
    txt.Visible := false;
  end;
end;
相关问题