首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在FireMonkey中调用数据感知(活动绑定)组件的刷新?

如何在FireMonkey中调用数据感知(活动绑定)组件的刷新?
EN

Stack Overflow用户
提问于 2018-11-07 03:52:43
回答 1查看 2.1K关注 0票数 4

我有一个用TListView连接在LiveBindings中的TFDMemTable。我使用FDMemTable (例如,有20条记录)在LoadFromFile中加载数据。

当我从FDMemTable中删除记录时,RecordCount会减少,但是TListView不会刷新,它将继续显示加载到LoadFormFile上的20条记录。

如果使用FDMemTable: i .SaveToFile.Close和使用.LoadFromFile重新加载,则TListView将显示更改。

如果我是否使用CachedUpdate of FDMemTable,这也是相同的行为。

我试着打电话给TFDMemTable.RefreshTListView.Repaint,但没有成功。

是否可以调用TListView来刷新他的“链接”数据集?

当我删除FDMemTable中的记录时,为什么TListView上没有可见的刷新?

编辑:我必须添加一个东西,记录是以编程方式删除的。

所需的功能是删除FDMemTable中不需要的记录,并使用TListView将剩余的记录显示给用户。

EN

回答 1

Stack Overflow用户

发布于 2018-11-07 08:53:26

这里的livebinding并不总是双向的。ListView livebinding被设计为从UI到dataset方向工作,但主要是。

如果您启用了CanSwipeDelete,那么如果您知道如何启用它,您就可以期待它的工作。

在我的例子中,在Android上,我发现自己正在编写代码,以确保listview与dataset保持同步,即使存在活动的livebinding。在我的例子中,是一个名为TClientDataset的CDSAnimals,它的唯一键值为TagID。我希望这能帮到你。

代码语言:javascript
复制
procedure TfrmLiveMain.ListView1DeletingItem(Sender: TObject; AIndex: Integer;
  var ACanDelete: Boolean);
var
  LI: TListViewItem;
  LIO: TListItemText;
begin

  // check that the livebindings is doing it's job, if not
  // do it myself
  ACanDelete := False;
  LI := ListView1.Items[AIndex];
  LIO := LI.Objects.FindObjectT<TListItemText>('Text1');
  FTagID := LIO.Text;
  if ClientModule2.CDSAnimals.FieldByName('TagID').AsString <> FTagID then
    ClientModule2.CDSAnimals.Locate('TagID', FTagID, []);
  if ClientModule2.CDSAnimals.FieldByName('TagID').AsString = FTagID then
  begin
    ACanDelete := True; // causes the listview item to be deleted without
                        // affecting the corresponding dataset record
  end;

end;

procedure TfrmLiveMain.ListView1DeleteItem(Sender: TObject; AIndex: Integer);
begin

  // this is called with the wrong index!
  if ClientModule2.CDSAnimals.Locate('TagID', FTagID, []) then
    if ClientModule2.CDSAnimals.FieldByName('TagID').AsString = FTagID then
      begin
        // now delete the corresponding record too
        ClientModule2.CDSAnimals.Delete; // and it works!
      end;

end;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53183347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档