怎么让DBGrid1的左边始终都有序列号???
也就是说不管其它数据怎么变,左边第一列始终都是按1、2、3、4、。排列下去了~~~

解决方案 »

  1.   

    如何让DBGRID显示序号? 修改GRID.pas
    在TCustomGrid.SetColWidths事件改为:
    procedure TCustomGrid.SetColWidths(Index: Longint; Value: Integer);
    begin
      if FColWidths = nil then
        UpdateExtents(FColWidths, ColCount, DefaultColWidth);
      if Index >= ColCount then InvalidOp(SIndexOutOfRange);
      if Value <> PIntArray(FColWidths)^[Index + 1] then
      begin
      if Value < 12 then Value := 30;   //新增
        ResizeCol(Index, PIntArray(FColWidths)^[Index + 1], Value);
        PIntArray(FColWidths)^[Index + 1] := Value;
        ColWidthsChanged;
      end;
    end;修改DBGRID.pas
    在procedure TCustomDBGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);事件加
    找到下面这一行
            FIndicators.Draw(Canvas, ALeft,
              (ARect.Top + ARect.Bottom - FIndicators.Height) shr 1, Indicator, True);
            if ACol <0 then
            begin
              Canvas.TextRect(ARect,0,(ARect.Top + ARect.Bottom - FIndicators.Height) shr 1
              ,inttostr(self.DataSource.DataSet.RecNo));
            end; //新增 
      

  2.   

    vickly(爱不存档) ( ) 信誉:87  2004-11-22 17:45:00  得分: 0  
     
     
       要求要保持不变哦~~不管其它字断怎么变,它都是固定的!
      
    楼主是不是想要这个效果?
    http://webmail.21cn.net:8082/tmp/230363_fsb:21cn_net/grideh.JPG
      

  3.   

    http://webmail.21cn.net:8082/tmp/230363_fsb:21cn_net/grideh.JPG
    如果楼主要的效果是这样的,实现方法有2个:
    1.每个左边放1个Panel,panel上写上1.2.3.4.5...
    2.用DbgridEh在可能引起dbgrideh重画的地方写如下代码:var
      I:Integer;
    begin
      for I:=0 to DBGridEh2.RowCount-2 do
      begin
        DBGridEh2.Canvas.Brush.Color:=clBtnFace;
        DBGridEh2.Canvas.TextOut(1,DBGridEh2.TitleHeight+5+(i*(DBGridEh2.RowHeight+1)),InttoStr(I+1));
      end;
    end;
    要设置DBGridEh的TitleHeight和RowHeight.
      

  4.   

    错了,用这个链接:
    http://webmail.21cn.net:8082/fcgi/file/grideh.JPG?action=download&filename=/1101365622
      

  5.   

    to:mastersky看不到效果.我的目的是:不管其它字断怎么排序,序号这一字断总是从1开始递增下去的,我要实现的是,让人知道,以某某字断排序的话,是排在第几位~~
      

  6.   

    看不到效果.我的目的是:不管其它字断怎么排序,序号这一字断总是从1开始递增下去的,我要实现的是,让人知道,以某某字断排序的话,是排在第几位~~1.在DataSet里建立一个计算字段:serial_1:Integer
    2.在这个字段的OnGetText事件中写:
      Text:=InttoStr(Sender.DataSet.RecNo);
    3.在DBGrid中使用这个字段即可.
      

  7.   

    在DBGrid中,可以让序号字断固定不变吗?不论后面的SQL语句有变化~~~
      

  8.   

    vickly(爱不存档) ( ) 信誉:87  2004-12-03 17:23:00  得分: 0  
     
     
       在DBGrid中,可以让序号字断固定不变吗?不论后面的SQL语句有变化~~~
      
     
    如果SQL语句有变化,只要字段不变就行。如果字段变了,这个方法就不行。
      

  9.   

    加一个字段,用一个循环来控制,
    var i:integer
    adoquery.first;
    for i:=1 to anumber(自己设定一个值) do begin
       adoquery.fieldbyname('xu').asinteger:=i;
       adoquery.next;
       end;
    adoquery.first;
      

  10.   

    http://www.delphibbs.com/delphibbs/dispq.asp?lid=2960059
      

  11.   

    1、如上所述的。
    2、如果有某个字段是按顺序排序的,例如1 2 4 6 7 (字段名:编号)
    select (select count(*) from table1 where 编号<a.编号) from table1 a
    3、如果是access,建立临时表,再用sql 命令 alter table 新建一自动编号字段
    4、如果是sql server ,用sql的 indentity函数
    5、如果是oralcal,--------->我不知道,我没用过,看,我连名字都拼错了。