【问题标题】:Delphi livebinding TClientDataSet TStringGrid runtimeDelphi livebinding TClientDataSet TStringGrid 运行时
【发布时间】:2013-09-23 15:04:47
【问题描述】:

在 Firemonkey (XE5) 中,我创建了一个带有 TStringGrid 的框架并想添加一个 “程序显示数据(aClientSet:TClientSet);” 在该程序中,Clientset 的行应使用 LiveBindings(TBindSourceDB ?)以只读方式显示,而无需了解数据集的任何其他内容并且没有 DESIGNER? 请问,这怎么能在运行时完成? 以及如何控制重新填充网格,如果数据集在框架之外关闭并重新打开(在哪里触发 TBindings.notify)? 谢谢。

【问题讨论】:

    标签: delphi runtime tclientdataset tstringlist delphi-xe5


    【解决方案1】:

    以下内容对我有用:

    1. 包括 Data.Bind.EngExt、Fmx.Bind.DBEngExt、Fmx.Bind.Grid、 System.Bindings.Outputs、Fmx.Bind.Editors、Data.Bind.Components、 使用子句中的 Data.Bind.Grid 和 Data.Bind.DBScope。
    2. 假设您的 TStringGrid 被命名为 grid1 并且您的数据集被称为 qry1 :

      变量
      bds: TBindSourceDB;
      bdl: TBindingsList;
      gtd: TLinkGridToDataSource;
      开始
      bds := TBindSourceDB.Create(Self);
      bdl := TBindingsList.Create(Self);
      gtd := TLinkGridToDataSource.Create(bdl);

        gtd.DataSource := bds;
      gtd.GridControl := Grid1;

        bds.DataSet := qry1;
      结束;

    希望这会有所帮助! (我使用 TFDQuery 作为我的数据集,但我确信任何 TDataset 后代都应该可以正常工作。)

    【讨论】:

      猜你喜欢
      • 2011-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 2010-10-14
      • 1970-01-01
      相关资源
      最近更新 更多