想在datagrid控件中加一列显示数据的序号,该怎样写??
是不是在DrawColumnCell事件中写吗???

解决方案 »

  1.   

    双击datagrid
    在弹出的对话框中点击 [Add New (Ins)]按钮
    指定新添加TColumn的FieldName等
      

  2.   

    双击DBGrid,先把所有字段加进去,再在最前面加一个字段,在DrawColumnCell中写
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; 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;