1.如果有id就好了,用通常改颜色的方法,在afterscroll里invalidate
2.
if (rect.top=(tstringgrid(dbgrid1).cellrect(tstringgrid(dbgrid1).col,
tstringgrid(dbgrid1).row).top)
and (not(gdfocused in state)) then
dbgrid1.canvas.brush.color:=clred;
dbgrid1.defaultdrawdatacell(rect,column.field,state)
一个小例子,在dx的CustomDrawCell事件中。
procedure TfrmMaterialCheck.dbDetailGrdCustomDrawCell(Sender: TObject;
ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode;
AColumn: TdxTreeListColumn; ASelected, AFocused, ANewItemRow: Boolean;
var AText: String; var AColor: TColor; AFont: TFont;
var AAlignment: TAlignment; var ADone: Boolean);
var fTemp: Single;
begin
if AText = '' then exit;
if (AColumn.Caption = '盘亏数量') or (AColumn.Caption = '盘亏金额') then
begin
try
fTemp := StrToFloat(AText);
except
end;
if fTemp > 0 then
AFont.Color := clRed;
end
else if (AColumn.Caption = '盘盈数量') or (AColumn.Caption = '盘盈金额') then
begin
try
fTemp := StrToFloat(AText);
except
end;
if fTemp > 0 then
AFont.Color := clLime;
end;
end;
…… ……
with Canvas do
begin
DrawColumn := Columns[ACol];
if not DrawColumn.Showing then exit;
if not (gdFixed in AState) then
begin
Font := DrawColumn.Font;
Brush.Color := DrawColumn.Color;
{你可以在这个begin和end之间,通过某种条件使Brush的Color为别的颜色
当然你也可以使Font也改变,从而使这一行颜色不同,其中DrawColumn.Color
使默认得颜色}
end;
…… ……
procedure TClientFrm.ClientGridCustomDrawCell(Sender: TObject;
ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode;
AColumn: TdxTreeListColumn; ASelected, AFocused, ANewItemRow: Boolean;
var AText: String; var AColor: TColor; AFont: TFont;
var AAlignment: TAlignment; var ADone: Boolean);
begin {画表格}
if not ANode.HasChildren then {这句在有分组时用}
begin
if ANode.Index mod 2 = 0 then {颜色间隔}
AColor := {颜色值}
else
AColor := {颜色值}
if ASelected then {选中的行}
begin
AFont.Color := {颜色值}
AColor := {颜色值}
end;
end;
end;