Cxgrid 单元格 内容 颜色 关键字高…

cxgrid 列表的列一定要手动提前绑定好。后期绑定的,颜色是会变不了的。注意了。因为我的列表全部都是自动从数据库加载的。搞了好几天。手动绑定列表之后。才可以变颜色了。

 

效果图片如下显示:Cxgrid <wbr>单元格 <wbr>内容 <wbr>颜色 <wbr>关键字高亮显示
procedure TXXXXXForm.GridViewCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);

var
  I,I1,I2,I3,I4: Integer;
  ViewCaption: string;
  ARec: TRect;  
  Column1,Column2,Column3,Column4: TcxGridColumn;
begin
  inherited;
  //变整行颜色
 { with ACanvas do
  begin
    if not VarIsNull(TcxGridDBTableView(Sender).DataController.DataSource.DataSet.FieldByName('C1').Value) then
    if  AViewInfo.GridRecord.DisplayTexts[TcxGridDBTableView(Sender).GetColumnByFieldName('C1').Index] = '空闲' then
    begin  //标识负数记录
      Canvas.Brush.Color:= $00669900;
      Canvas.Font.Color:= clWhite;//clActiveCaption
    end;
  }
{颜色分为四种:空闲 $00669900 试用 $00FF99FF  使用 $00CA66FF  请假 $0033CCFF }
   I1 := -1;
   I2 := -1;
   I3 := -1;
   I4 := -1;
   with  (Sender as TcxGridDBTableView) do
   begin
     for I := 0 to ColumnCount - 1 do
     begin
       if UpperCase(Columns[I].DataBinding.FieldName)='C1' then
       begin
         I1 := I;
         Column1 := GetColumnByFieldName('C1');
       end
       else if UpperCase(Columns[I].DataBinding.FieldName)='C2' then
       begin
         I2 := I;
         Column2 := GetColumnByFieldName('C2');
       end
       else
       if UpperCase(Columns[I].DataBinding.FieldName)='C3' then
       begin
         I3 := I;
         Column3 := GetColumnByFieldName('C3');
       end
       else if UpperCase(Columns[I].DataBinding.FieldName)='C4' then
       begin
         I4 := I;
         Column4 := GetColumnByFieldName('C4');
       end;
     end;
   end;
   if (Column1 = nil) and (Column2=nil) and (Column3 = nil) and (Column4=nil)  then
     Exit;

   //这个条件用来限制是否只Paint指定的单元格, 去掉则Paint整行.
    if SameText(AViewInfo.Item.Name, Column1.Name) then
   begin             
     if AViewInfo.GridRecord.Values[I1] = null then Exit;
     ViewCaption := AViewInfo.GridRecord.Values[I1]; //获取单元格
     //以下是满足条件的字体变色
      if Pos('空闲',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $00669900;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('试用',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $00FF99FF;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('使用',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $00CA66FF;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('请假',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $0033CCFF;
         ACanvas.Font.Color := clblack ;
      end
      else
      begin
         ACanvas.Font.Color := clWhite;
         ACanvas.Brush.Color := clblack ;
      end;
   end
   else if SameText(AViewInfo.Item.Name, Column2.Name) then
   begin
     if AViewInfo.GridRecord.Values[I2] = null then Exit;
     ViewCaption := AViewInfo.GridRecord.Values[I2]; //获取单元格
     //以下是满足条件的字体变色
      if Pos('空闲',ViewCaption) > 0  then
      begin
         ACanvas.Brush.Color := $00669900;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('试用',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $00FF99FF;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('使用',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $00CA66FF;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('请假',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $0033CCFF;
         ACanvas.Font.Color := clblack ;
      end
      else
      begin
         ACanvas.Font.Color := clWhite;
         ACanvas.Brush.Color := clblack ;
      end;
   end
   else if SameText(AViewInfo.Item.Name, Column3.Name) then
   begin
     if AViewInfo.GridRecord.Values[I3] = null then Exit;
     ViewCaption := AViewInfo.GridRecord.Values[I3]; //获取单元格
     //以下是满足条件的字体变色
      if Pos('空闲',ViewCaption) > 0  then
      begin
         ACanvas.Brush.Color := $00669900;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('试用',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $00FF99FF;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('使用',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $00CA66FF;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('请假',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $0033CCFF;
         ACanvas.Font.Color := clBlack;
      end
      else
      begin
         ACanvas.Font.Color := clWhite;
         ACanvas.Brush.Color := clblack ;
      end;
   end
   else if SameText(AViewInfo.Item.Name, Column4.Name) then
   begin
     if AViewInfo.GridRecord.Values[I4] = null then Exit;
     ViewCaption := AViewInfo.GridRecord.Values[I4]; //获取单元格
     //以下是满足条件的字体变色
      if Pos('空闲',ViewCaption) > 0  then
      begin
         ACanvas.Brush.Color := $00669900;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('试用',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $00FF99FF;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('使用',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $00CA66FF;
         ACanvas.Font.Color := clWhite ;
      end
      else if Pos('请假',ViewCaption) > 0 then
      begin
         ACanvas.Brush.Color := $0033CCFF;
         ACanvas.Font.Color := clblack ;
      end
      else
      begin
         ACanvas.Font.Color := clWhite;
         ACanvas.Brush.Color := clblack ;
      end;
   end ;
end;

 

效果图片如下显示:Cxgrid <wbr>单元格 <wbr>内容 <wbr>颜色 <wbr>关键字高亮显示

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值