delphi Cxdbgrid 根据单元格数据使单元格改变颜色

来源:互联网 发布:snmp 端口 161 162 编辑:程序博客网 时间:2024/05/09 17:44

procedure TForm1.cxGrid1DBTableView1CustomDrawCell(  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);//var//  abc:Integer;             //整行var   CheckValue:integer;          //單元格   cxColumn:TcxGridColumn;        //整列begin{  abc:=AViewInfo.GridView.FindItemByName('cxGrid1DBTableView1Column4').Index;    if AViewInfo.GridRecord.Values[abc]=True and ((AViewInfo.RecordViewInfo.GridRecord.Values[4])='0') then  begin    AViewInfo.GridRecord.Values[aa]=True and AViewInfo.    ACanvas.Brush.Color:=clRed;  end;}  cxColumn:=(Sender as TcxGridDBTableView).GetColumnByFieldName('Full_Name');//獲取列  if cxColumn=nil then Exit;

  if SameText(AViewInfo.Item.Name,cxColumn.Name) then    //限制是否只Paint指定的單元格條件  begin     CheckValue:=AViewInfo.GridRecord.Values[cxGrid1DBTableView1Column4.Index];   //獲取單元格條件     if CheckValue>10 then         //單元格背景變色條件        begin         AViewInfo.Focused;         ACanvas.Brush.Color:=clRed;        end;

     if CheckValue>20 then       begin         AViewInfo.Focused;         ACanvas.Brush.Color:=clGreen;       end;

     if CheckValue>30 then       begin         AViewInfo.Focused;         ACanvas.Brush.Color:=clBlue;       end;    end;end;

原创粉丝点击