zoukankan      html  css  js  c++  java
  • 怎样在DbGrid的左边,实现像EXCEL那样的自动编号?

    unit Unit1;

    interface

    uses
     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
     Grids, DBGrids, StdCtrls, Buttons, Db, DBTables, ExtCtrls, jpeg;
    const ROWCNT=20;

    type
        tmygrid=class(tdbgrid)
        protected
          procedure Paint;override;
          procedure DrawCell(ACol:Integer;ARow:Integer;ARect:TRect;AState:TGridDrawState);override;
        public
          constructor create(AOwner:TComponent);override;
          destructor  destroy;override;
        end;

     TForm1 = class(TForm)
       BitBtn1: TBitBtn;
       DataSource1: TDataSource;
       Table1: TTable;
       procedure BitBtn1Click(Sender: TObject);
     private
       { Private declarations }
     public
       { Public declarations }
     end;

    var
     Form1: TForm1;
     mygrid:tmygrid;
    implementation

    {$R *.DFM}

        {tmygrid}
        constructor tmygrid.create(AOwner:TComponent);
        begin
           inherited create(Owner);
           RowCount:=ROWCNT;
        end;

        destructor tmygrid.destroy;
        begin
          inherited;
        end;

        procedure tmygrid.Paint;
        begin
          RowCount:=ROWCNT;
          if dgIndicator in options then
             ColWidths[0]:=30;
          inherited;
        end;

        procedure tmygrid.DrawCell(ACol:Integer;ARow:Integer;ARect:TRect;AState:TGridDrawState);
        begin
          inherited;
          if (ARow>=1) and (ACol=0) then
             Canvas.TextRect(ARect,ARect.Left,ARect.Top,IntToSTr(ARow));
       end;

    procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
     mygrid:=tmygrid.create(Self);
     mygrid.parent:=self;
     mygrid.left:=0;
     mygrid.top:=0;
     mygrid.Height:=300;
     mygrid.DataSource:=DataSource1;
    end;

    end.

  • 相关阅读:
    Servlet学习总结,为理解SpringMVC底层做准备
    maven笔记
    初识Hadoop
    java8笔记: sorted()之正序倒序
    git push命令
    git clone新项目后如何拉取其他分支代码到本地
    Spring事务
    线程之间的转化状态
    Centos安装RabbitMq
    .net 中的AES加密解密
  • 原文地址:https://www.cnblogs.com/beeone/p/1792349.html
Copyright © 2011-2022 走看看