M
marco_hsu
Unregistered / Unconfirmed
GUEST, unregistred user!
cxGrid怎样才能根据字段值行显示不同颜色了?
现在我可以根据已有列显示不同颜色,可我的列是动态产生的,所以名字不能确定,也有可能对应字段不会在COLUMN列中出现,特别是状态字段,该怎么设置了:
procedure TForm1.cxGrid1DBTableView1CustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var str:string;
begin
str:=trim(VarAsType(AViewInfo.GridRecord.DisplayTexts[ColumnSex.Index], varString));
if str='男' then
begin
ACanvas.Canvas.Brush.Color :=clred;
ACanvas.canvas.Font.Color := clblack;
end
else if str='女' then
begin
ACanvas.Canvas.Brush.Color :=clgreen;
ACanvas.canvas.Font.Color := clblack;
end;
if AViewInfo.Selected then
begin
ACanvas.Canvas.Font.Color := clwhite;
ACanvas.Canvas.Brush.Color :=clNavy ;
end;
我想改成和DBGRIDEH那样可以根据某个查询字段来改变
现在我可以根据已有列显示不同颜色,可我的列是动态产生的,所以名字不能确定,也有可能对应字段不会在COLUMN列中出现,特别是状态字段,该怎么设置了:
procedure TForm1.cxGrid1DBTableView1CustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var str:string;
begin
str:=trim(VarAsType(AViewInfo.GridRecord.DisplayTexts[ColumnSex.Index], varString));
if str='男' then
begin
ACanvas.Canvas.Brush.Color :=clred;
ACanvas.canvas.Font.Color := clblack;
end
else if str='女' then
begin
ACanvas.Canvas.Brush.Color :=clgreen;
ACanvas.canvas.Font.Color := clblack;
end;
if AViewInfo.Selected then
begin
ACanvas.Canvas.Font.Color := clwhite;
ACanvas.Canvas.Brush.Color :=clNavy ;
end;
我想改成和DBGRIDEH那样可以根据某个查询字段来改变