DBGridEh的Title(表头)动态赋值

      with Dm_Main.ADOQuery_Temp do
      begin
        Sql_Open(Format('select distinct wxxm_no,wxxm_mc from sm_tongji_xm where GongSiNo = ''%S'' ', [GongSiNo]), Dm_Main.ADOQuery_Temp);
        with DBGridEh_temp do
        begin
          for i := 0 to Columns.Count - 1 do
          begin
            if Dm_Main.ADOQuery_Temp.Locate('wxxm_no', Columns[i].Field.DisplayLabel, []) then
              Columns[i].Field.DisplayLabel := Dm_Main.ADOQuery_Temp.FieldByName('wxxm_mc').AsString
            else if LowerCase(Columns[i].FieldName) = 'reco_no' then
            begin
              Columns[i].Field.DisplayLabel := '序号';
              Columns[i].Visible := False;
            end
            else if LowerCase(Columns[i].FieldName) = 'flag_bs' then
            begin
              Columns[i].Field.DisplayLabel := '内部标识';
              Columns[i].Visible := False;
            end
            else if LowerCase(Columns[i].FieldName) = 'xche_jsrq' then
            begin
              Columns[i].Field.DisplayLabel := '结算日期';
              Columns[i].HideDuplicates := True;
            end
            else if LowerCase(Columns[i].FieldName) = 'work_no' then
            begin
              Columns[i].Field.DisplayLabel := '维修单号';
              Columns[i].HideDuplicates := True;
            end
            else if LowerCase(Columns[i].FieldName) = 'che_no' then
            begin
              Columns[i].Field.DisplayLabel := '车牌号码';
              Columns[i].HideDuplicates := True;
            end
            else if LowerCase(Columns[i].FieldName) = 'kehu_mc' then
            begin
              Columns[i].Field.DisplayLabel := '客户名称';
              Columns[i].HideDuplicates := True;
            end
            else if LowerCase(Columns[i].FieldName) = 'xche_bz' then
            begin
              Columns[i].Field.DisplayLabel := '说明';
            end
            else if LowerCase(Columns[i].FieldName) = 'xche_heji' then
            begin

              Columns[i].Field.DisplayLabel := '合计';

              Columns[i].Footer.ValueType := fvtSum;

            end;
            //打印时0不显示
            if Columns[i].Field is TBCDField then
              Columns[i].Field.OnGetText := HideZeroGetText;
            //标题居中
            Columns[i].Title.Alignment := taCenter;

            if Columns[i].Field is TStringField then
              Columns[i].Width := 100
            else
              Columns[i].Width := 80;
          end;
        end;

      end;

    //ADOQuery中,TFloatField设置DisplayFormat

      with ADOQuery do
      begin
        for I := 0 to Fields.Count - 1 do
        begin
          if LowerCase(fields[I].Classname) = 'tfloatfield' then
          begin
            with Fields[I] as TFloatField do
            begin
              DisplayFormat := '0.00';
            end;              
          end;
        end;  
      end;

-------------------

procedure HideZeroGetText(Sender: TField;
  var Text: String; DisplayText: Boolean);

begin
  if Sender is TBCDField then
  begin
    if Sender.AsFloat = 0 then
      Text :=''
    else
      Text :=  Sender.AsString;
  end;
end;


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值