一dbgrid的字段显示的问题! 先搜索一下好吗………………在OnDrawColumnCell中处理 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //==============================================================================//根据状态设置Cell颜色******************************************************//==============================================================================procedure TForm_BillManage.DBGridDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);begin if Column.Field.FieldName='状态' then begin //===================================================================== if Column.Field.AsString='正常' then begin DBGrid.Canvas.Brush.Color := DBGrid.Color; DBGrid.Canvas.Font.Color := clBlack; //DBGrid.Canvas.Brush.Color := States[0].CellColor; //DBGrid.Canvas.Font.Color := States[0].FontColor; end; //===================================================================== if Column.Field.AsString='丢失' then begin DBGrid.Canvas.Brush.Color := States[3].CellColor; DBGrid.Canvas.Font.Color := States[3].FontColor; end; //===================================================================== if Column.Field.AsString='作废' then begin DBGrid.Canvas.Brush.Color := States[6].CellColor; DBGrid.Canvas.Font.Color := States[6].FontColor; end; end; //============================================================================ DBGrid.DefaultDrawDataCell(Rect, Column.Field, State);end; 好例子unit MainFrm;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Db, DBTables, Grids, DBGrids, ComCtrls, StdCtrls, ExtCtrls;type TMainForm = class(TForm) dbgMain: TDBGrid; Query2: TQuery; DataSource1: TDataSource; dbgSecond: TDBGrid; Label4: TLabel; Label5: TLabel; procedure dbgMainDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); procedure dbgSecondDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); private { Private declarations } public { Public declarations } end;var MainForm: TMainForm;implementation{$R *.DFM}procedure TMainForm.dbgMainDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);begin if gdSelected in State then Exit; if Query2.RecNo mod 2 = 0 then dbgMain.Canvas.Brush.Color := clInfoBk else dbgMain.Canvas.Brush.Color := RGB(191, 255, 223); dbgMain.DefaultDrawColumnCell(Rect,DataCol,Column,State); dbgMain.Canvas.Pen.Color := $00C08000; dbgMain.Canvas.MoveTo(Rect.Left, Rect.Bottom); dbgMain.Canvas.LineTo(Rect.Right, Rect.Bottom); dbgMain.Canvas.MoveTo(Rect.Right, Rect.Top); dbgMain.Canvas.LineTo(Rect.Right, Rect.Bottom);end;procedure TMainForm.dbgSecondDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);begin with dbgSecond.Canvas do begin Pen.Color := clBlue; MoveTo(Rect.Left, Rect.Bottom); LineTo(Rect.Right, Rect.Bottom); Pen.Color := clGreen; MoveTo(Rect.Right, Rect.Top); LineTo(Rect.Right, Rect.Bottom); end;end;end. delphi2007串口控件安装 有没有办法自己控制hint的显示? 求如何取某月的天数??? 有这样的吗? 求援:delphi4与delphi6的兼容问题 问各位:杭州或者上海或者华东地区用delphi为主要开发工具并且象点样的公司有多少? NTSERVER中调用SHELLAPI大多会失败,请问是怎么回事? 如何直接调用系统自带的那个调整日期窗体呀 关于数据显示问题。 菜鸟问题,答对者给分哟!!!! 用DELPHI生成不可逆密文的算法,此密文要求存入数据库中某字段 有没有选择文件的控件
//根据状态设置Cell颜色******************************************************
//==============================================================================
procedure TForm_BillManage.DBGridDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Column.Field.FieldName='状态'
then begin
//=====================================================================
if Column.Field.AsString='正常'
then begin
DBGrid.Canvas.Brush.Color := DBGrid.Color;
DBGrid.Canvas.Font.Color := clBlack;
//DBGrid.Canvas.Brush.Color := States[0].CellColor;
//DBGrid.Canvas.Font.Color := States[0].FontColor;
end;
//=====================================================================
if Column.Field.AsString='丢失'
then begin
DBGrid.Canvas.Brush.Color := States[3].CellColor;
DBGrid.Canvas.Font.Color := States[3].FontColor;
end;
//=====================================================================
if Column.Field.AsString='作废'
then begin
DBGrid.Canvas.Brush.Color := States[6].CellColor;
DBGrid.Canvas.Font.Color := States[6].FontColor;
end;
end;
//============================================================================
DBGrid.DefaultDrawDataCell(Rect, Column.Field, State);
end;
unit MainFrm;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, Grids, DBGrids, ComCtrls, StdCtrls, ExtCtrls;type
TMainForm = class(TForm)
dbgMain: TDBGrid;
Query2: TQuery;
DataSource1: TDataSource;
dbgSecond: TDBGrid;
Label4: TLabel;
Label5: TLabel;
procedure dbgMainDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure dbgSecondDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;var
MainForm: TMainForm;implementation{$R *.DFM}procedure TMainForm.dbgMainDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if gdSelected in State then
Exit;
if Query2.RecNo mod 2 = 0 then
dbgMain.Canvas.Brush.Color := clInfoBk
else
dbgMain.Canvas.Brush.Color := RGB(191, 255, 223); dbgMain.DefaultDrawColumnCell(Rect,DataCol,Column,State);
dbgMain.Canvas.Pen.Color := $00C08000;
dbgMain.Canvas.MoveTo(Rect.Left, Rect.Bottom);
dbgMain.Canvas.LineTo(Rect.Right, Rect.Bottom);
dbgMain.Canvas.MoveTo(Rect.Right, Rect.Top);
dbgMain.Canvas.LineTo(Rect.Right, Rect.Bottom);
end;procedure TMainForm.dbgSecondDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with dbgSecond.Canvas do
begin
Pen.Color := clBlue;
MoveTo(Rect.Left, Rect.Bottom);
LineTo(Rect.Right, Rect.Bottom);
Pen.Color := clGreen;
MoveTo(Rect.Right, Rect.Top);
LineTo(Rect.Right, Rect.Bottom);
end;
end;end.