1:單元格的值滿足某個條件時,該單元格所在整行顏色設置整行字體設置
選中cxGridDBTableView,單擊F11調出屬性配置面板,在Events中雙擊OnCustomDrawCell后雙擊編輯重畫事件代碼。
代碼如下:
if '1' = AViewInfo.GridRecord.Values[cxgrdbclmnGridDBTableView5ysbj.Index] then begin //整行背景顏色設置 //ACanvas.Canvas.Brush.Color := clGreen; //整行字體顏色設置 //ACanvas.Font.Color := clGreen; end;
2:單元格的值滿足某個條件時,該單元格背景/字體顏色的設置
添加樣式准備:
拖一個cxStyleRepository1控件,雙擊該控件進行Styles的添加和設置;
2:選中cxGridDBTableView,單擊F11調出屬性配置面板,在Events中雙擊OnGetContentStyle后雙擊編輯重畫事件代碼。
代碼如下:
1 procedure TFrm_Qry_DBLT.cxGrid1DBTableView1StylesGetContentStyle( 2 Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; 3 AItem: TcxCustomGridTableItem; out AStyle: TcxStyle); 4 begin 5 if ARecord is TcxGridDataRow then 6 //and not ARecord.Selected then //選中行導出沒有顏色 7 begin 8 if ARecord.Values[cxGrid1DBTableView1.GetColumnByFieldName('CQ').Index] > 1 then 9 AStyle := cxStyle1 //屬於 TcxStyleRepository 10 end; 11 end;
1 procedure TMainFrm.cxGridHisDBTableView1CustomDrawCell( 2 Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; 3 AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean); 4 begin 5 //第7列顏色改變 6 if (AViewInfo.Item.ID = 6) then 7 begin 8 ACanvas.Brush.Color := clred; 9 end; 10 11 end;
注意:只有cxStyleRepository1設定的樣式被cxGrid應用,cxGrid導致到Excel時才帶有顏色。
作者:Jeremy.Wu
出處:https://www.cnblogs.com/jeremywucnblog/
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。