zoukankan      html  css  js  c++  java
  • 学用 TStringGrid [3] Cols、Rows

    须知: TStringGrid 的每行、每列都是一个 TStrings 对象.

    本例功能:
    1、分别按列与行修改;
    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;
        Button3: TButton;
        Button4: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    {按列赋值}
    procedure TForm1.Button1Click(Sender: TObject);
    var
      List: TStrings;
    begin
      List := TStringList.Create;
      List.CommaText := 'aaa,bbb,ccc,ddd';
      StringGrid1.Cols[0] := List;
      StringGrid1.Cols[1] := List;
      List.Free;
      (Sender as TButton).Caption := '按列赋值';
    end;
    
    {按行赋值}
    procedure TForm1.Button2Click(Sender: TObject);
    var
      List: TStrings;
    begin
      List := TStringList.Create;
      List.CommaText := '111,222,333,444';
      StringGrid1.Rows[0] := List;
      StringGrid1.Rows[1] := List;
      List.Free;
      (Sender as TButton).Caption := '按行赋值';
    end;
    
    {按列取值}
    procedure TForm1.Button3Click(Sender: TObject);
    var
      List: TStrings;
    begin
      List := StringGrid1.Cols[StringGrid1.Col]; {当前列}
      ShowMessage(List.Text);
      (Sender as TButton).Caption := '按列取值';
    end;
    
    {按行取值}
    procedure TForm1.Button4Click(Sender: TObject);
    var
      List: TStrings;
    begin
      List := StringGrid1.Rows[StringGrid1.Row]; {当前行}
      ShowMessage(List.Text);
      (Sender as TButton).Caption := '按行取值';
    end;
    
    end.
    
  • 相关阅读:
    elementUI 表格分页后台排序记录
    oracle乱码记录
    JavaScript 数字转汉字+element时间选择器快速选择
    js中call()方法和apply方法的使用
    Rails导出CSV
    CakePHP2.x 发送邮件
    一个例子说明substr(), mb_substr() 和 mb_strcut()之间的区别
    substr是不安全的
    CakePHP中回调函数的使用
    cakephp中find('list')的使用
  • 原文地址:https://www.cnblogs.com/del/p/1091588.html
Copyright © 2011-2022 走看看