如何在DBGrid1中加入序号 请高手指点 谢谢
解决方案 »
- 当鼠标移动到一个位置后,显示其全部内容,如何实现
- swap函数的用法!
- 如何获得TWebBrowser当前鼠标所在位置的控件名称?
- 谢谢诸位大虾一路来的关照,现在又有新问题了:D7光盘上附的INSTALLSHIELD是3.5,我不会打包DBXPRESS/MS SQL连接。。。
- 有关BIG5-->UTF-8编码问题
- 关于DBCHART的问题
- 改变资源字符串的值
- Delphi调用TADOStoredProc出错的问题,在线等候
- 想实现这样一个功能,就是想当在edit中输入四个字符后触发事件,或者说在edit失去focus后触发事件。
- 谁能解释一下窗体的ondestroy事件何时触发
- 关于TStringGrid问题?
- 送分讨论请教水晶报表(Crystal report9组件在Delphi7中的应用
当增加新记录的时候 Query.FieldByName(计算字段名).asInteger:=TStringGrid(DBgrid).Row;
你可以
with DataSet do
begin
if RecNo > 0 then
FieldByName('ID').AsInteger := RecNo
else
FieldByName('ID').AsInteger := 1;
end;就是增加一个字段
加一个计算字段
在这个计算字段的OnGetText事件写上:
Text:=IntToStr(Query.RecNo);
因为Query.RecNo的默认为-1
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with DBGrid1.DataSource.DataSet do
begin
if DataCol = 0 then//第一列
DBGrid1.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, IntToStr(RecNo));
end;
end;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if Column.Index = 0 then
with DBGrid1.Canvas do
begin
FillRect(Rect);
TextOut(Rect.Left+2, Rect.Top+2, IntToStr(DBGrid1.DataSource.DataSet.RecNo));
end;
end;
procedure SetColumnAttributes; override; //设置左边那个固定栏的宽....procedure TDBGroupGridEh.SetColumnAttributes;
begin
inherited; if (dgIndicator in Options) then
ColWidths[0] := 40;end;其它的按楼上的楼上的代码.
自己写的一个控件中显示行号的一段代码
procedure RGrid.ShowRowNo;
var i,iCount:Integer;begin
if FixedCols<1 then Exit;//如果没有序号区则不用显示行号
iCount:=1;
for i:=FixedRows to RowCount-1 do
begin
Cells[0,i]:=IntToStr(iCount);
iCount:=iCount+1;
end;
end;
应该用ADOQuery
加一个计算字段
在这个计算字段的OnGetText事件写上:
Text:=IntToStr(Query.RecNo);
取RecNo的值,每一条记录都为-1吖
还是未能实现显示序号的目的吖