procedure TForm1.DBGridEh4DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState); begin if adoquery3.FieldByName('run_status').AsString<>'Success' then begin dbgrideh4.Canvas.Font.Color:=clred ; dbgrideh4.Canvas.Brush.Color:=clwhite; end else begin dbgrideh4.Canvas.Font.Color:=clblack; dbgrideh4.Canvas.Brush.Color:=clwhite; if gdFocused in state then dbgrideh4.Canvas.Brush.Color:=clyellow; end; dbgrideh4.DefaultDrawColumnCell(rect,datacol,column,state); end; 包呆(380505802) 20:39:48 自己改改 fanhongbin(61460464) 12:44:43 请问一下,那如何用代码实现选定Cell,并变色 fanhongbin(61460464) 12:45:16 包呆,你上CSDN吧,我在CSDN也问了,到那儿,我给分你。 fanhongbin(61460464) 12:46:04 在DELPHIVCL组件开发及应用版 包呆(380505802) 20:46:28 TGridDrawState = set of (gdSelected, gdFocused, gdFixed);
在Delphi 7 中测试通过。 if gdSelected in State then begin TwwDBGRID.Canvas.Brush.Color := clNavy; TwwDBGRID.Canvas.Font.Color := clWhite; end; TwwDBGRID.DefaultDrawColumnCell(Rect,DataCol,Column,State);
在Delphi 7 中测试通过。procedure TForm1.TwwDBGRIDDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState); begin if gdSelected in State then begin TwwDBGRID.Canvas.Brush.Color := clNavy; TwwDBGRID.Canvas.Font.Color := clWhite; end; TwwDBGRID.DefaultDrawColumnCell(Rect,DataCol,Column,State); end;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if adoquery3.FieldByName('run_status').AsString<>'Success' then
begin
dbgrideh4.Canvas.Font.Color:=clred ;
dbgrideh4.Canvas.Brush.Color:=clwhite;
end
else
begin
dbgrideh4.Canvas.Font.Color:=clblack;
dbgrideh4.Canvas.Brush.Color:=clwhite;
if gdFocused in state then
dbgrideh4.Canvas.Brush.Color:=clyellow;
end;
dbgrideh4.DefaultDrawColumnCell(rect,datacol,column,state);
end;
包呆(380505802) 20:39:48
自己改改
fanhongbin(61460464) 12:44:43
请问一下,那如何用代码实现选定Cell,并变色
fanhongbin(61460464) 12:45:16
包呆,你上CSDN吧,我在CSDN也问了,到那儿,我给分你。
fanhongbin(61460464) 12:46:04
在DELPHIVCL组件开发及应用版
包呆(380505802) 20:46:28
TGridDrawState = set of (gdSelected, gdFocused, gdFixed);
fanhongbin(61460464) 12:49:32
Twwdbgrid中有这个吗,我试一下,先
fanhongbin(61460464) 12:50:11
这个怎么用呢?
包呆(380505802) 20:49:06
onDrawColumnCell事件里
fanhongbin(61460464) 12:52:10
可不可以不在事件里写,在一个过程里面写,可以吗?
包呆(380505802) 20:50:44
为什么不写在事件里?
fanhongbin(61460464) 12:54:49
是这样的,我想在运行期,在form点一个按钮,然后就选定某一行,或者选定某一个单元格,然后,变色或者得到焦点
fanhongbin(61460464) 12:55:57
就是在做数据检查的时候,要回到原来位置,并高亮
fanhongbin(61460464) 12:56:53
我用了Twwdatainspector组件,不知道如何做这些处理,总达不到理想的效果
fanhongbin(61460464) 12:56:53
我用了Twwdatainspector组件,不知道如何做这些处理,总达不到理想的效果?
onDrawColumnCell事件已经提供了很好的平台
干吗不写到里面?
判断选择行的基偶是最简单的一种改变颜色
或者判断选定的记录的某个条件是否满足
begin
TwwDBGRID.Canvas.Brush.Color := clNavy;
TwwDBGRID.Canvas.Font.Color := clWhite;
end; TwwDBGRID.DefaultDrawColumnCell(Rect,DataCol,Column,State);
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if gdSelected in State then
begin
TwwDBGRID.Canvas.Brush.Color := clNavy;
TwwDBGRID.Canvas.Font.Color := clWhite;
end; TwwDBGRID.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;