zoukankan      html  css  js  c++  java
  • CxGrid的使用说明

    CxGrid的使用说明

     

    cxgrid分组自动展开
    cxgrdbtblvwGrid1DBTableView1.DataController.Groups.FullExpand

    cxgrid取得默认字段

    cxgrdbtblvwGrid1DBTableView1.ClearItems;
    cxgrdbtblvwGrid1DBTableView1.DataController.CreateAllItems;

     

    (1)动态设置显示格式
    procedure SetDisplayFormat(ACtrlData: TClientDataSet;
       TbView: TcxGridDBTableView);
    var
       i: integer;
    begin
       if ACtrlData.RecordCount <= 0 then Exit;
       try
         TbView.ClearItems;
         ACtrlData.First;
         for i := 0 to ACtrlData.RecordCount - 1 do
         begin
           if ACtrlData.FieldByName('SQBF_DisplayInGrid').AsString = '1' then //在表格中显示
           with TbView.CreateColumn do
           begin
             DataBinding.FieldName := ACtrlData.FieldByName('SQBF_FieldName').AsString;
             Caption := ACtrlData.FieldByName('SQBF_Caption').AsString; //字段中文标题
             Hint := ACtrlData.FieldByName('SQBF_Hint').AsString;
             Width := ACtrlData.FieldByName('SQBF_Width').AsInteger;
             HeaderAlignmentHorz := taCenter;
           end;
           ACtrlData.Next;
         end;
       except
         on E: Exception do
           SaveLog('设置显示格式时出错:' + E.Message);
       end;
    end;

    (2)显示行号
    procedure TFmQueryBase.cxDBViewMasterCustomDrawIndicatorCell(
       Sender: TcxGridTableView; ACanvas: TcxCanvas;
       AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    var
       FValue: string;
       FBounds: TRect;
    begin
       FBounds := AViewInfo.Bounds;
       if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
       begin
         ACanvas.FillRect(FBounds);
         ACanvas.DrawComplexFrame(FBounds, clBlack, clBlack, [bBottom, bLeft, bRight], 1);
         FValue := IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index+1);
         InflateRect(FBounds, -3, -2); //Platform specific. May not work on Linux.
         ACanvas.Font.Color := clBlack;
         ACanvas.Brush.Style := bsClear;
         ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
         ADone := True;
       end;
    end;
    (3)设置显示格式,我的项目要求先动态添加字段,这时不知道字段类型,所以设置DisplayFormat不方便,我还没有找到好方法。
    所以采用打开数据集后再设置:
    procedure TFmQueryBase.cdsMasterAfterOpen(DataSet: TDataSet);
    var
       i: Integer;
    begin
       for i := 0 to cxDBViewMaster.DataController.DataSet.FieldCount -1 do
       begin
         if cxDBViewMaster.DataController.DataSet.Fields[i] is TNumericField then
         begin
           if Pos('AMOUNT', UpperCase(cxDBViewMaster.DataController.DataSet.Fields[i].FieldName)) > 0 then
           begin
             TNumericField(cxDBViewMaster.DataController.DataSet.Fields[i]).DisplayFormat := '#,##0.000';
             Continue;
           end;
           if Pos('QUANTITY', UpperCase(cxDBViewMaster.DataController.DataSet.Fields[i].FieldName)) > 0 then
           begin
             TNumericField(cxDBViewMaster.DataController.DataSet.Fields[i]).DisplayFormat := '#,##0.000';
             Continue;
           end;
            if Pos('MONEY', UpperCase(cxDBViewMaster.DataController.DataSet.Fields[i].FieldName)) > 0 then
           begin
             TNumericField(cxDBViewMaster.DataController.DataSet.Fields[i]).DisplayFormat := '#,##0.00';
             Continue;
           end;
        end;
       end;
    end;

  • 相关阅读:
    springboot和数据库链接关于取名的一些坑
    个人作业——软件评测
    结对第二次作业——某次疫情统计可视化的实现
    结对第一次—疫情统计可视化(原型设计)
    软工实践寒假作业(2/2)
    个人作业——软件工程实践总结&个人技术博客
    个人技术总结——Vxe-table
    个人作业——软件评测
    结对第二次作业——某次疫情统计可视化的实现
    结对第一次—疫情统计可视化(原型设计)
  • 原文地址:https://www.cnblogs.com/karkash/p/3104224.html
Copyright © 2011-2022 走看看