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.
    
  • 相关阅读:
    《代码大全》阅读心得一
    vi列模式
    以指定的概率/机会获取元素
    自用VIM配置
    优雅的Javascript
    关于遮罩层
    CSS3属性BorderRadius详解[圆角]
    CSS3属性boxshadow详解[盒子阴影]
    CSS3文字特效
    Css3 Animation详解
  • 原文地址:https://www.cnblogs.com/del/p/1090799.html
Copyright © 2011-2022 走看看