zoukankan      html  css  js  c++  java
  • 学用 TStringGrid [1] ColCount、RowCount、Cells

    本例功能:
    1、获取 StringGrid 的行数、列数;
    2、给单元赋值.

    运行效果图:


    //示例代码:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, Grids;
    
    type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        Panel1: TPanel;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    {显示列数与行数}
    procedure TForm1.Button1Click(Sender: TObject);
    var
      cCount,rCount: Integer;
    begin
      cCount := StringGrid1.ColCount; {获取总列数}
      rCount := StringGrid1.RowCount; {获取总行数}
    
      Text := Format('总列数: %d; 总行数: %d', [cCount, rCount]); {显示在标题}
    end;
    
    {给每个单元赋值}
    procedure TForm1.Button2Click(Sender: TObject);
    var
      c,r: Integer;
    begin
      for c := 0 to StringGrid1.ColCount - 1 do
        for r := 0 to StringGrid1.RowCount - 1 do
          StringGrid1.Cells[c,r] := Format('%d,%d', [c,r]);
    end;
    
    end.
    
  • 相关阅读:
    备用
    Python进阶
    *args 和 **kwargs
    C语言
    【Pythno库】-Re
    【C语言】-struct
    Django By Example
    字符串
    Python库
    【Keil】Keil5-改变字的大小和颜色
  • 原文地址:https://www.cnblogs.com/del/p/1090799.html
Copyright © 2011-2022 走看看