• [转载]FastReport 报表排序与cxGrid同步.


         //描述: cxGrid的 TableView 数据排序与对应的数据集同步, 该方法主要用于打印时
           //         的排序与所见到的排序保持一致;
           //参数: @tv: 排序的cxGridTableView
           //说明: @tv: 对应的数据集只支持 ADOQuery与 ClientDataSet;
           procedure cxGridSortSyncToDataSet(tv: TcxGridDBTableView); overload;

           //描述: 功能同上, 实现代码一样, 如果有更改就同步更改
           procedure cxGridSortSyncToDataSet(tv: TcxGridDBBandedTableView); overload;

    procedure cxGridSortSyncToDataSet(tv: TcxGridDBTableView);
    const
         SortArray: array[soAscending..soDescending] of string = ('ASC', 'DESC');
    var
         AscFields, DescFields, S, SortOrder: string;
         IndexPrint: string;
         I: integer;
         Index: integer;
         cds: TClientDataSet;
    begin
         S := '';
         AscFields := '';
         DescFields := '';
         if tv.SortedItemCount = 0 then
           Exit;
         if tv.DataController.DataSource.DataSet is TADOQuery then begin
           for I := 0 to tv.SortedItemCount - 1 do begin
             SortOrder := SortArray[tv.SortedItems[I].SortOrder];
             if S <> '' then
               S := S + ', ';
             Index := tv.SortedItems[I].Index;
             S := S + tv.Columns[Index].DataBinding.Field.FieldName + ' ' + SortOrder;
           end;
           (tv.DataController.DataSource.DataSet as TADOQuery).Sort := S;
         end else if (tv.DataController.DataSource.DataSet is TClientDataSet)     then begin
           Cds := tv.DataController.DataSource.DataSet as TClientDataSet;
           for I := 0 to tv.SortedItemCount - 1 do begin
             Index := tv.SortedItems[I].Index;
             S := tv.Columns[Index].DataBinding.Field.FieldName +';';
             AscFields := AscFields + S;
             if tv.SortedItems[I].SortOrder = soDescending then
               DescFields := DescFields + S;
           end;
           if AscFields <> '' then
             Delete(AscFields, Length(AscFields), 1); //删除 ;

           if DescFields <> '' then
             Delete(DescFields, Length(DescFields), 1);
           IndexPrint := TimeToStr(Now());
           Cds.IndexDefs.Clear;
           IndexPrint := TimeToStr(Now());
           cds.AddIndex(IndexPrint, AscFields, [], DescFields);
           cds.IndexName := IndexPrint;
         end;
    end;

  • 相关阅读:
    Win32应用中创建多窗口
    同时控制多个UIScrollView对象
    在后台代码中设定控件的Visibility
    VC中使用GDI+
    悬垂指针(Dangling pointer)和野指针(Wild pointer)
    在Windows下通过命令行界面编译并生成 .exe
    C++流重定向到文件
    读写文本文件和二进制文件——二进制模式
    使用MahApps.Metro
    WPF之GUI编写
  • 原文地址:https://www.cnblogs.com/eastson/p/1656757.html
Copyright © 2020-2023  润新知