下面我的dbgrid中显示的代码,如何将记录号加到dbgrid 列中,谢谢了!
qq1:=tadoquery.Create(self);
qq1.Connection:=conn;
with qq1 do
begin
close;
sql.Clear;
sql.Add('select id,haoma as 号码,guishu as 归属地,tongxunming as 通讯公司 from haoma ');
open;
end;
datasource1.DataSet:=qq1;
dbgrid1.DataSource:=datasource1;
qq1:=tadoquery.Create(self);
qq1.Connection:=conn;
with qq1 do
begin
close;
sql.Clear;
sql.Add('select id,haoma as 号码,guishu as 归属地,tongxunming as 通讯公司 from haoma ');
open;
end;
datasource1.DataSet:=qq1;
dbgrid1.DataSource:=datasource1;
解决方案 »
- cxgrid的问题。
- .pas文件如何引用?是不是只要users ***(pas文件名就可以了)
- 刷新是用adoquery1.close;adoquery1.open;如何在刷新后光标回到当前记录(该录不在最后和最前,不定位)
- 如何在一串字符串里把我需要我内容取来放入TSringList内???
- com应用问题
- 帮忙改个函数!
- 两个小问题。
- 主窗口中调用dll中的一个子窗口时数据访问的问题
- 在线呢..谁知道李维的delphi5.x分布式系统篇的例子程序哪有的down???
- 我用ole链接word文件,为何只显示文件的第一页,其它页不显示,怎样解决,若在OLE中无法解决,还有何方法可以读取word文件?
- 由上网中病毒木马所想到的...与网页中使用ocx,cab包有关。
- DBGrid怎样实现自适应列宽,找过一些代码,可是都不如意
procedure TDBGridEh.DrawCell(ACol:Integer;ARow:Integer;ARect:TRect;AState:TGridDrawState);
var
i,DBRow,lLeft:integer;
iCol,iRow:integer; //全局变量
begin
inherited; {是否开启显示行号功能!}
if fShowRecNo=True then
begin
if Assigned(DataLink) and
DataLink.Active then //没有open
begin
if (ARow>=1) and
(ACol=0) then{行标头之内}
begin
i := 0;//偏移值
lLeft := 0;//居中显示
DBRow := self.DataSource.DataSet.RecNo;//当前数据集所在的行标 rec no
if DataSource.DataSet.RecNo=-1 then{新增记录状态}
begin
DBRow := DataSource.DataSet.RecordCount+1;//当前行标取记录总数+1
end;
i := DBRow - self.Row ;//计算表格TopRow和数据集所在行的偏移值(显示实际数据集行号)
lLeft := (ARect.Right - ARect.Left) div 2 - Canvas.TextWidth(IntToSTr({DataLink.ActiveRecord}ARow+i)) div 2;//居中显示
Canvas.TextRect(ARect,ARect.Left+lLeft,ARect.Top,IntToSTr({DataLink.ActiveRecord}ARow+i));//输出行号
end;
end;
end;
end;
2、代码:procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if DataSource1.DataSet.RecNo > 0 then
begin
if WideUpperCase(Column.Title.Caption) = '序号' then
DBGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Top, IntToStr(DataSource1.DataSet.RecNo));
end;
end;