当DBGridEh中某网格的数据被改变时,如何改变此网格的背景颜色?(200分)

  • 主题发起人 主题发起人 jqjiang
  • 开始时间 开始时间
J

jqjiang

Unregistered / Unconfirmed
GUEST, unregistred user!
为了让用户更清楚地看到哪些数据被修改了,需要这样的处理。
 
只是改网格背景很简单,只要在ondrawcell事件自画就行了,但你要知道哪个格变化就有点麻烦,可以考虑加个字段保存状态等
 
可是
procedure TForm7_shujuluru.DBGridEh1DrawDataCell(Sender: TObject;
const Rect: TRect;
Field: TField;
State: TGridDrawState);
begin
if dbgrideh1.Fields[dbgrideh1.Col-1].OldValue <> dbgrideh1.Fields[dbgrideh1.Col-1].NewValue
then
dbgrideh1.Canvas.Font.Color:=clblue
else
dbgrideh1.Canvas.Font.Color:=clWindow;
DBGridEh1.DefaultDrawDataCell(Rect,Field,State);
end;
改变的是一行的颜色,我只想改变一个格子的颜色。
 
給你來段我的,也許能幫到你。。
----------------------------------------------------------------
procedure TfrmAttenDance.dbgrdh1DrawColumnCell(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumnEh;
State: TGridDrawState);
begin
if (dbgrdh1.DataSource.DataSet.FieldByName('result1').Value='ゼゴ') and(DataCol=10)then
dbgrdh1.Canvas.Font.Color:=clRed;
dbgrdh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
if (dbgrdh1.DataSource.DataSet.FieldByName('result1').Value='筐?') and (DataCol=10) then
dbgrdh1.Canvas.Font.Color:=clFuchsia;
//
dbgrdh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
if (dbgrdh1.DataSource.DataSet.FieldByName('result2').Value='ゼゴ') and(DataCol=12)then
dbgrdh1.Canvas.Font.Color:=clRed;
dbgrdh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
if (dbgrdh1.DataSource.DataSet.FieldByName('result2').Value='Ν癶') and (DataCol=12) then
dbgrdh1.Canvas.Font.Color:=clBlue;
dbgrdh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
if (dbgrdh1.DataSource.DataSet.FieldByName('result3').Value='ゼゴ') and(DataCol=14)then
dbgrdh1.Canvas.Font.Color:=clRed;
if (gdSelected in State) then
begin
dbgrdh1.Canvas.Brush.Color:=clOlive;
dbgrdh1.Canvas.Font.Color:=clBlack;
dbgrdh1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end
end;
 
DataCol這個控制某個東東,哈哈。。。
 
dbgrid 控件应该和他差不多吧。
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect;//
DataCol: Integer;
Column: TColumn;
State: TGridDrawState);
begin

if gdSelected in State then
Dbgrid1.Canvas.Brush.Color:=clred;//红色
Dbgrid1.DefaultDrawColumnCell( Rect, DataCol, Column, [gdFixed,gdFocused,gdSelected]);

end;
//选中的单元格换颜色,在DBGRID的OPTION里选中
//ROWSELECTED为TRUE。就是一行了。
 
想在第二列的颜色改变添加“(DataCol=2)”,如下程序更改:
同时不是在drawdatacell中写,而是drawcolumncell中进行写函数,
//procedure TForm7_shujuluru.DBGridEh1DrawDataCell(Sender: TObject;
//const Rect: TRect;
Field: TField;
State: TGridDrawState);
procedure TForm7_shujuluru.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumnEh;
State: TGridDrawState);
begin
if dbgrideh1.Fields[dbgrideh1.Col-1].OldValue <> dbgrideh1.Fields[dbgrideh1.Col-1].NewValue and (DataCol=2)
then
dbgrideh1.Canvas.Font.Color:=clblue
else
dbgrideh1.Canvas.Font.Color:=clWindow;
TDBGrideh(Sender).DefaultDrawColumnCell(Rect,DataCol,Column,State);
//DBGridEh1.DefaultDrawDataCell(Rect,Field,State);
end;
 
多人接受答案了。
 
后退
顶部