如何设置DBGrid中某一单元格中数据的颜色,如:设置Cell(3,6)单元格的颜色为红色
解决方案 »
- DM真的可以用来放共享变量吗?
- 如何使用Delphi与Usb设备进行通讯
- 图形学习代码!!delphi,gdi,gdi+(热卖中)
- 【跳楼前最后一问】:动态创建控件的问题,谁来解释解释????
- WebBrowse的打开进度条?
- 请问北京的个人所得税是多少?为什么我领工资时,比承诺的少了200多元呢?
- 查了有关目录,文件的函数没找到,问一下各位,怎样判断一个目录是否为空目录?
- 事务问题的写法?
- adotable的时间过滤问题,在线!!
- 有什么方法可以获得页面信息
- 在debug命令以后,粘贴下列文本的内容,会让你下一跳~~~(原文太长了,我分两次发布)1
- ▼▲ 看起来容易的问题其实很不好解决 ---> 如何判断一个指针是否有效。
用下面这个改造一下,试试
procedure TdfrmSt_Decl.DBGrid2DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
inherited;
IF column.FieldName='IfPur' then
begin
IF column.Field.AsBoolean=true then
begin
DBGrid2.Canvas.Font.Height:=12;
DBGrid2.Canvas.TextRect(Rect,Rect.left+1,Rect.top+1,'');
end
Else
begin
DBGrid2.Canvas.Font.Height:=12;
DBGrid2.Canvas.TextRect(Rect,Rect.left+1,Rect.top+1,'·ñ');
end;
end;
end; IF Column.Field.AsBoolean then
begin
DBGrid2.Canvas.Font.Color:=clGreen;
DBGrid2.Canvas.Font.Height:=12;
DBGrid2.Canvas.Font.Style:=[fsBold];
DBGrid2.Canvas.TextRect(Rect,Rect.Left+1,Rect.Top+1,' ¡Ì')
want to use the dgRowSelect option because you want to be able
to edit the data you can use the following technique on the
DBGrid.OnDrawColumnCell event:type
TCustomDBGridCracker = class(TCustomDBGrid);
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with Cracker(Sender) do
if DataLink.ActiveRecord = Row - 1 then
Canvas.Brush.Color := clRed
else
Canvas.Brush.Color := clWhite;
DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
* 过程名:SetGridColor
* 过程说明: 用于设置数据库应用程序的DBGrid的数据显示时的颜色
* 可在TDBGrid的DrawColumnCell事件中进行设置,例如:
* SetGridColor(TDataSet(CompanyADTable),DBGrid1,Rect,DataCol,Column,State);* 参数说明:
* AdoTable:数据库对象名称(可重载,可以使用ADOTABLE,ADOQUERY,TTABLE,TQUERY对象.全部从TDataSet中继承得来)
* DbGrid1:要显示的数据库TDBGRID对象
* Rect,DataCol,Column,State:这四个参数可全部从TDBGrid的DrawColumnCell事件中传递过来!
*******************************************************************************)Procedure SetGridColor(Var AdoTable:TDataSet;Var DbGrid1:TDBGrid;const Rect: TRect; DataCol: Integer;
Column: TColumn; State: TGridDrawState);
begin
Case AdoTable.RecNo mod 2 = 0 of // file://根据数据集的记录号进行判断
True: DbGrid1.Canvas.Brush.color:=clcream;// file://偶数行用浅绿色显示
False: DbGrid1.Canvas.Brush.color:= clwhite;// file://奇数行用蓝色表示
end;
If ((State = [gdSelected]) or (State=[gdSelected,gdFocused])) then
Case DataCol mod 2 = 0 of
True :
begin
DbGrid1.Canvas.Brush.color:=$00ffff; //file://当前选中行的偶数列用红色
dbgrid1.Canvas.Font.Color:=clred;
end;
False:
begin
DbGrid1.Canvas.Brush.color:=$00ffff;// file://当前选中行的奇数列用绿色表示
dbgrid1.Canvas.Font.Color:=clred;
end;
end;
DbGrid1.Canvas.pen.mode:=pmMask;
DbGrid1.DefaultDrawColumnCell (Rect, DataCol, Column, State);
end;