我问的如何在DBGrid表格控件中为表格添加色带的问题,即第一行为灰色,第二行为白色,第三行为灰色,第四行为白色,依次类推,只能在Delphi自带的数据库中实现, 拜托,实现这个与数据库没有关系,使DBGRid自己的事情,难怪没有人回答你,看看delphi的帮助 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你只要自己指定dbgrid的ondrawcolumn事件就可以了,确实与数据库没有关系 本人确实试了又试,Access和SQL的数据库就是不行,不信请自己试一下。但还是要请高手帮忙。procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);begin if query1.recno mod 2<>0 then dbgrid1.canvas.Brush.color:=$00eaeaea; dbgrid1.DefaultDrawcolumnCell(rect,datacol,column,state);end; RecNo 只对 Paradox tables有效,其他的数据表一律都是-1不变看来你可以定义一个外部变量来代表了油标的移动了 用ADO Query连接数据就可以用RecNo啦! 还是没有人告诉我,在Acess.SQL数据库中怎样实现DBGrid表格控件中的色带问题。难道你们都不会吗? 下载一个组件就可以了:http://delphicoms.at.china.com//////////////////////////////////////////////////////////////////// 显示斑马线格式的 DBGrid 的组件 //// Program by PengFuZhang 2000.06.20 //// Email:[email protected] ////////////////////////////////////////////////////////////////////unit DBGridC;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids;type TDBGridC = class(TDBGrid) private { Private declarations } FC1:TColor; FC2:TColor; protected { Protected declarations } procedure DrawCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); public { Public declarations } Constructor Create(AOwner: TComponent); override; Procedure Scroll(Distance: Integer); override; Procedure About; published { Published declarations } Property C1:TColor Read FC1 Write FC1; Property C2:TColor Read FC2 Write FC2; end;procedure Register;implementationProcedure TDBGridC.About;Begin Application.MessageBox('PPanel 作者:彭富张 2000.03 Email:[email protected]','关于 PPanel',MB_OK+MB_ICONINFORMATION);End;Constructor TDBGridC.Create(AOwner: TComponent);Begin inherited Create(AOwner); C1:=$00E1FFFF; C2:=$00D3FED6; OnDrawColumnCell:=DrawCell;End;procedure TDBGridC.DrawCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);Var HPR:Integer;Begin If dgRowLines in Options Then HPR:=Rect.Bottom-Rect.Top+1 Else HPR:=Rect.Bottom-Rect.Top; If ((Rect.Top Div HPR) Mod 2)=0 Then Canvas.Brush.Color:=FC1 Else Canvas.Brush.Color:=FC2; DefaultDrawColumnCell(Rect, DataCol, Column, State);End;procedure TDBGridC.Scroll(Distance: Integer);Begin inherited Scroll(Distance); Refresh;End;procedure Register;begin RegisterComponents('SLGIS', [TDBGridC]);end;end. to:AP() 感谢AP()同志的帮助, 似乎代码也太长了吧!,是否不用组件也能实现能。 其实不困难,只要在判断行号时不使用数据库就可以了。以下是示例:procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);var iRow,iGridHeight : Integer;begin iGridHeight := Rect.Bottom - Rect.Top; iRow := (Rect.Top - iGridHeight ) div iGridHeight; if iRow mod 2 <> 0 then dbgrid1.canvas.Brush.color:=$00eaeaea; dbgrid1.DefaultDrawcolumnCell(rect,datacol,column,state);end; to ameng007(阿门): 感谢ameng007(阿门)的帮助,就让我试一试。 to ameng007(阿门): 再次感谢您给我的帮助, 经过调试,顺利通过你的方法, 但程序运行起来显得不够稳定,能否有更好的办法, 请广大的的delphi朋友加入进来。好吗! 当然我会给ameng(阿门)加20分。 为什么有些USES的 单元无法打开查看 请问如下的报表应当如何用RAVE 实现 TCHART做柱状图问题 不好意思我把问题说具体些: 如何判断sqlserver2000数据库中的某个表是否存在?在线。 我是个贱人!!!! 请教indy控件高手 关于 microsoft help workshop的问题 这段程序是怎么回事啊,请大家帮帮忙?很急 如何向dos屏幕送一个字符串,像c中的printf 请大侠们指点一下人生 有谁知道如何控制浏览器的边框?
但还是要请高手帮忙。
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if query1.recno mod 2<>0 then dbgrid1.canvas.Brush.color:=$00eaeaea;
dbgrid1.DefaultDrawcolumnCell(rect,datacol,column,state);
end;
看来你可以定义一个外部变量来代表了油标的移动了
难道你们都不会吗?
// 显示斑马线格式的 DBGrid 的组件 //
// Program by PengFuZhang 2000.06.20 //
// Email:[email protected] //
//////////////////////////////////////////////////////////////////unit DBGridC;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids;type
TDBGridC = class(TDBGrid)
private
{ Private declarations }
FC1:TColor;
FC2:TColor;
protected
{ Protected declarations }
procedure DrawCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
public
{ Public declarations }
Constructor Create(AOwner: TComponent); override;
Procedure Scroll(Distance: Integer); override;
Procedure About;
published
{ Published declarations }
Property C1:TColor Read FC1 Write FC1;
Property C2:TColor Read FC2 Write FC2;
end;procedure Register;implementationProcedure TDBGridC.About;
Begin
Application.MessageBox('PPanel 作者:彭富张 2000.03 Email:[email protected]','关于 PPanel',MB_OK+MB_ICONINFORMATION);
End;Constructor TDBGridC.Create(AOwner: TComponent);
Begin
inherited Create(AOwner);
C1:=$00E1FFFF;
C2:=$00D3FED6;
OnDrawColumnCell:=DrawCell;
End;procedure TDBGridC.DrawCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
Var HPR:Integer;
Begin
If dgRowLines in Options Then
HPR:=Rect.Bottom-Rect.Top+1
Else
HPR:=Rect.Bottom-Rect.Top; If ((Rect.Top Div HPR) Mod 2)=0 Then
Canvas.Brush.Color:=FC1
Else
Canvas.Brush.Color:=FC2;
DefaultDrawColumnCell(Rect, DataCol, Column, State);
End;procedure TDBGridC.Scroll(Distance: Integer);
Begin
inherited Scroll(Distance);
Refresh;
End;procedure Register;
begin
RegisterComponents('SLGIS', [TDBGridC]);
end;end.
感谢AP()同志的帮助,
似乎代码也太长了吧!,是否不用组件也能实现能。
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
iRow,iGridHeight : Integer;
begin
iGridHeight := Rect.Bottom - Rect.Top;
iRow := (Rect.Top - iGridHeight ) div iGridHeight;
if iRow mod 2 <> 0 then dbgrid1.canvas.Brush.color:=$00eaeaea;
dbgrid1.DefaultDrawcolumnCell(rect,datacol,column,state);
end;
感谢ameng007(阿门)的帮助,就让我试一试。
再次感谢您给我的帮助,
经过调试,顺利通过你的方法,
但程序运行起来显得不够稳定,能否有更好的办法,
请广大的的delphi朋友加入进来。好吗!
当然我会给ameng(阿门)加20分。