求能显示行号的DBGridEh控件!(可加分) ( 积分: 200 )

  • 主题发起人 主题发起人 FormatBrain
  • 开始时间 开始时间
F

FormatBrain

Unregistered / Unconfirmed
GUEST, unregistred user!
如题!
联系QQ:19523609
 
如题!
联系QQ:19523609
 
需要在DBGrid增加一列作行号。
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids;

type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
procedure DataSource1StateChange(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
{ Private declarations }
FirstRecNo: integer;
public
{ Public declarations }
end;

TDataSetEx= class(TDataSet);

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DataSource1StateChange(Sender: TObject);
begin
with TDataSource(Sender) do
begin
FirstRecNo := DataSet.RecordCount - TDataSetEx(DataSet).ActiveRecord;
end;
end;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
i: integer;
begin
Inherited;
with TDBGrid(sender) do
begin
if (DataCol =0) then
begin
if DataSource.State <> DsInsert then
i:= DataSource.DataSet.RecNo
else
i:= FirstRecNo + Rect.Top div 19;
Canvas.TextRect(rect,Rect.Left+2, Rect.Top+2, inttostr(i));
end;
end;
end;

end.
 
这个我已经能在程序中实现,而且可以实现为把行号打印在加宽了的Indicator列上。
但是我想实现的是,把加行号的功能写成一个增加的DBGridEh。
 
我也实现过,不过不完美,希望切磋一下
 
我的思路和“鳄鱼先生”的差不多!
 
TO:mrxuhua
你实现在效果如何呢?
 
用DBGridEh1,在QUERY中加一個計算字段,用于作為行号(為字符),然後在
procedure Tfrmseasonadjuste.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin

end;
中寫如下:
with DBGridEh1.DataSource.DataSet do
begin
if DataCol = 0 then//第一列
DBGridEh1.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, IntToStr(RecNo));
end;
 

Similar threads

D
回复
0
查看
925
DelphiTeacher的专栏
D
D
回复
0
查看
717
DelphiTeacher的专栏
D
D
回复
0
查看
678
DelphiTeacher的专栏
D
后退
顶部