for i := 0 to DBGridEh的列数 -1 do begin
if (值的大小判断) and (Column.FieldName= 某一单元格字段名) then
DBGridEh1.Canvas.Brush.Color := clRed
end;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
//网上有很多一整行变色的例子,要达到你的要求关键在于后面一个判断
改进一下:
1.用OnCellClik事件,把你要更改的字段的值保存到全局变量(假设tmp)中.
2.在OnDrawColumnCell事件里面写:
if DBGrid1.DataSource.DataSet.Modified then
DBGrid1.DataSource.DataSet.Post;
if (比较现在的值和tmp的值) then
begin
DBGrid1.Canvas.Brush.Color:=clSkyBlue; //蓝色
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end
else
begin
DBGrid1.Canvas.Brush.Color:=clRed; //红色
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end
1.用OnCellClik事件,把你要更改的字段的值保存到全局变量(假设tmp)中.
2.在OnDrawColumnCell事件里面写:
if (比较现在的值和tmp的值) then
begin
DBGrid1.Canvas.Brush.Color:=clSkyBlue; //蓝色
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end
else
begin
DBGrid1.Canvas.Brush.Color:=clRed; //红色
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end