cxgrid改变选中行颜色

简介:

procedure Tfrm_select_case_model_other.dw_1CustomDrawCell(
 Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
 AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  ARec: TRect;
begin
 if AViewInfo.Focused then
 begin
   ARec := AViewInfo.Bounds;
   ACanvas.canvas.brush.color:= clSkyBlue;
   ACanvas.Font.Color := clRed;
   ACanvas.FillRect(ARec);
 end
 else
 begin
   ARec := AViewInfo.Bounds;
   ACanvas.canvas.brush.color:= clWhite;
   ACanvas.Font.Color := clBlack;
   ACanvas.FillRect(ARec);
 end;

end;


var
  ARec: TRect;
  i:integer;
begin
  if AViewInfo.Focused then
  begin
   ARec := AViewInfo.Bounds;
   ACanvas.canvas.brush.color:= clSkyBlue;
   ACanvas.Font.Color := clRed;
   ACanvas.FillRect(ARec);
  end
  else
  begin
   ARec := AViewInfo.Bounds;
   ACanvas.canvas.brush.color:= clWhite;
   ACanvas.Font.Color := clBlack;
   ACanvas.FillRect(ARec);
  end;
  if (AViewInfo.Item.Index = 18) or (AViewInfo.Item.Index = 19) or
    (AViewInfo.Item.Index = 33) or (AViewInfo.Item.Index = 34) or
    (AViewInfo.Item.Index = 48) or (AViewInfo.Item.Index = 49) then
  begin
    ARec := AViewInfo.Bounds;
    ACanvas.canvas.brush.color:= clSkyBlue;
    ACanvas.FillRect(ARec);
  end;
  if (AViewInfo.Item.Index >= 6) and (AViewInfo.Item.Index <= 19) then
  for i := 6 to 19 do
  begin
    if vartostr(AViewInfo.RecordViewInfo.GridRecord.Values[i])= '-' then
    begin
      ARec := AViewInfo.Bounds;
      ACanvas.Font.Color := clRed;
      ACanvas.FillRect(ARec);
    end;
  end;
  if (AViewInfo.Item.Index >= 21) and (AViewInfo.Item.Index <= 34) then
  for i := 21 to 34 do
  begin
    if vartostr(AViewInfo.RecordViewInfo.GridRecord.Values[i]) = '-' then
    begin
      ARec := AViewInfo.Bounds;
      ACanvas.Font.Color := clRed;
      ACanvas.FillRect(ARec);
    end;
  end;



procedure TFm_Rkcx.GD_RkcxBTCustomDrawCell(Sender: TcxCustomGridTableView;
 

ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
 var ADone: Boolean);
var ATextToDraw:String;
  ARec: TRect;
begin
 ATextToDraw := AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index];
 ARec := AViewInfo.Bounds;
 if AViewInfo.GridRecord.Values[6]<1000 then
  ACanvas.Canvas.Font.Color := clRed;
 //整行变色:ACanvas.Canvas.brush.color:=clred;  
 {列的颜色交替
  if AViewInfo.Item.Index mod 2 = 0 then
   ACanvas.Canvas.brush.color := clInfoBk
  else
  ACanvas.Canvas.brush.color := clInactiveCaptionText;
 }
 {行的颜色交替
   if AViewInfo.RecordViewInfo.Index mod 2 = 0 then
  ACanvas.Canvas.brush.color := clInfoBk
 else
  ACanvas.Canvas.brush.color := clInactiveCaptionText; 
 } 
 ACanvas.Canvas.FillRect(ARec);
end;


如果第一个字段的值小于125,用红色背景显示,文字为居中显示

procedure TForm1.cxGrid1DBTableView1CustomDrawCell(
 Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
 AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
   if StrToInt(AViewInfo.GridRecord.DisplayTexts[0])<125 then
    begin
      ACanvas.Brush.Color:=clRed;
      ACanvas.FillRect(AViewInfo.Bounds);
      ACanvas.DrawText(AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index], AViewInfo.Bounds, cxAlignHCenter);
      ADone:=true;
    end;
end;  














本文转自鹅倌51CTO博客,原文链接: http://blog.51cto.com/kaixinbuliao/1219463  ,如需转载请自行联系原作者
相关文章
|
6月前
|
C#
C# DEV 关于设置gridview 指定单元格字体为红色
C# DEV 关于设置gridview 指定单元格字体为红色
|
C++
VS C++改变窗体背景色
VS C++改变窗体背景色
158 0
设置CListCtrl网格线
设置CListCtrl网格线
203 0
C#编程-78:DataGridView隔行显示不同颜色
C#编程-78:DataGridView隔行显示不同颜色
323 0
C#编程-78:DataGridView隔行显示不同颜色
C#编程-76:DataGridView当前行显示不同颜色
C#编程-76:DataGridView当前行显示不同颜色
238 0
C#编程-76:DataGridView当前行显示不同颜色
改变DBGRID的选中行的颜色
默认DBGRID选中行的颜色为深蓝色,可以在程序中改变 在DBGRID的OnDrawColumnCell中写入 if (State=[gdSelectd..gdFocused,gdCurrent]) then begin    Grid.
884 0
改变UITableView选中行高亮的颜色
改变UITableView选中行高亮的颜色
115 0
改变ListBoxItem选中的颜色
原文:改变ListBoxItem选中的颜色 改变ListBoxItem主要是改变的style   下面直接看代码吧!!! 1 2 3 4 5 ...
817 0