Delphi StringGrid 实例4 本例功能: 1、给每个单元格赋值 2、调整当前单元格位置:上下左右;


本文整理自网络,侵删。

 
实例4

本例功能:
1、给每个单元格赋值
2、调整当前单元格位置:上下左右;
 运行效果图:


type

 TForm12 = class(TForm)

    StringGrid1: TStringGrid;

    StringColumn1: TStringColumn;

    StringColumn2: TStringColumn;

    StringColumn3: TStringColumn;

    StringColumn4: TStringColumn;

    StringColumn5: TStringColumn;

    Panel1: TPanel;

    Button1: TButton;

    Button2: TButton;

    Button3: TButton;

    Button4: TButton;

    procedure FormCreate(Sender: TObject);

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

    procedure Button4Click(Sender: TObject);

 private

    { Private declarations }

 public

    { Public declarations }

 end;

var

      Form12: TForm12;

 

implementation

{赋值}

procedure TForm12.FormCreate(Sender: TObject);
var
      i,j: Integer;
begin
      with StringGrid1 do
            for i := 0 to ColumnCount - 1 do
                   for j := 0 to RowCount - 1 do
                            Cells[i,j] := Format('%d%d',[i,j]);
end;

procedure TForm12.Button1Click(Sender: TObject);
begin
      if StringGrid1.ColumnIndex < StringGrid1.ColumnCount-1 then
        StringGrid1.ColumnIndex := StringGrid1.ColumnIndex + 1;
         Button1.Text:='单元格右移';
end;

procedure TForm12.Button2Click(Sender: TObject);
begin
        if StringGrid1.ColumnIndex > 0 then
                 StringGrid1.ColumnIndex := StringGrid1.ColumnIndex- 1;
                 Button2.Text:='单元格左移';
end;

 

procedure TForm12.Button3Click(Sender: TObject);
begin
    if StringGrid1.Selected< StringGrid1.RowCount-1 then
          StringGrid1.Selected := StringGrid1.Selected+ 1;
          Button3.Text:='单元格上移';

end;

procedure TForm12.Button4Click(Sender: TObject);
begin
             if StringGrid1.Selected > 0 then
                       StringGrid1.Selected := StringGrid1.Selected- 1;
                        Button4.Text:='单元格下移';

end;
end.

来源:https://www.cnblogs.com/lingzhiwen/p/3322570.html

相关阅读 >>

Delphi 双击tmemo选择光标所在行

Delphi getcomputername() getusername() 获取本机当前用户名

Delphi randomize 随机数

Delphi实现ping功能的类

Delphi 虚拟桌面原理及实现

Delphi 将程序加裁到启动项

Delphi通过idhttp和php交互

Delphi实现类似嵌入桌面的效果

Delphi 外挂编写的几个api函数

Delphi 从一个html返回所有的图片链接

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...