⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 在delphi的stringgrid控件中的任意行删除和增加行
💻 ~PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure DeleteRow(Row: Integer);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
Procedure GridAddColumn(StrGrid: TStringGrid; NewColumn: Integer);
Var Column: Integer;  
begin
StrGrid.rowCount := StrGrid.rowCount+1;
For Column := StrGrid.rowCount-1 downto NewColumn do
 StrGrid.rows[Column].Assign(StrGrid.rows[Column-1]);
  StrGrid.rows[NewColumn-1].Text := '';
  end;

procedure TForm1.DeleteRow(Row: Integer);
var 
i : integer; 
begin 
if (Row<StringGrid1.RowCount) and (Row>Stringgrid1.FixedRows-1) then
if (Row<StringGrid1.RowCount-1) then
begin
for i:=Row to StringGrid1.RowCount-1 do
StringGrid1.Rows[i]:=StringGrid1.Rows[i+1];
StringGrid1.RowCount:=StringGrid1.RowCount-1;
end
else stringGrid1.Rows[Row].Clear;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Sel : TGridRect;

begin
Sel:=StringGrid1.Selection;
DeleteRow(Sel.Top);

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
stringgrid1.Cells[1,1]:='23';
stringgrid1.Cells[1,2]:='56';
stringgrid1.Cells[1,3]:='47';
end;

procedure TForm1.Button2Click(Sender: TObject);
var 
Sel : TGridRect;
begin
Sel := StringGrid1.Selection;
GridAddColumn(stringgrid1,Sel.Top);

end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -