【问题标题】:Problems with IndexFieldNames in firemonkey (FMX)firemonkey (FMX) 中的 IndexFieldNames 问题
【发布时间】:2022-01-27 11:35:19
【问题描述】:

该问题仅在 firemonkey 中出现。使用 VCL 可以完美运行。

我有一个数据集(任何类型)连接到一个网格(任何类型) 单击列标题时,必须按相应字段排序。

VCL

procedure TForm2.DBGrid1TitleClick(Column: TColumn);
begin
  qrySec.IndexFieldNames := Column.FieldName;
end;

FMX

procedure TManFarmaQry.StringGrid1HeaderClick(Column: TColumn);
begin
     
case Column.Index of
          0:
            if mtblMedica.IndexFieldNames = 'Field1' then
              mtblMedica.IndexFieldNames := 'Field1' + ':D'
            else
              mtblMedica.IndexFieldNames := 'Field1';
    
          1:
            if mtblMedica.IndexFieldNames = 'Field2' then
              mtblMedica.IndexFieldNames := 'Field2' + ':D'
            else
              mtblMedica.IndexFieldNames := 'Field2';
          2:
            if mtblMedica.IndexFieldNames = 'Field3' then
              mtblMedica.IndexFieldNames := 'Field3' + ':D'
            else
              mtblMedica.IndexFieldNames := 'Field3';
        end;
end;

在 FMX 的情况下,可以观察到寄存器的重新排列,但它不对应任何内容。把所有东西都弄得乱七八糟。

我认为由于这两种情况都使用了 Firedac,所以问题不存在。然后是bind中的同步问题。

德尔福 10.3.3

【问题讨论】:

    标签: sorting delphi indexing grid firemonkey


    【解决方案1】:

    希望我找到的解决方案对其他人有帮助,我把它留在这里。

    procedure TManFarmaQry.StringGrid1HeaderClick(Column: TColumn);
    begin
      // Putting things practical    
          if mtblMedica.IndexFieldNames = LinkGridToDataSourceBindSourceDB1.Columns[Column.Index].MemberName then
            mtblMedica.IndexFieldNames := LinkGridToDataSourceBindSourceDB1.Columns[Column.Index].MemberName + ':D'
          else
            mtblMedica.IndexFieldNames := LinkGridToDataSourceBindSourceDB1.Columns[Column.Index].MemberName;
    
        
        // Here is the solution. Refresh datasource
            LinkGridToDataSourceBindSourceDB1.Active := False;
            LinkGridToDataSourceBindSourceDB1.Active := True;
    
    end;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-14
      • 2022-12-15
      相关资源
      最近更新 更多