StringGrid 实例3: 本例功能: 1、修改 TStringGrid的默认宽与高; 2、添加行; 3、确认当前单元并赋值.

实例3:

本例功能:
1
、修改 TStringGrid的默认宽与高;
2
、添加行;
3
、确认当前单元并赋值.

实例图形:

unit Unit12;

 

interface

 

uses

 System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,

 System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Grid,

 FMX.Layouts;

 

type

 TForm12 = class(TForm)

    StringGrid1: TStringGrid;

    Panel1: TPanel;

    Button1: TButton;

    Button2: TButton;

    StringColumn1: TStringColumn;

    StringColumn2: TStringColumn;

    StringColumn3: TStringColumn;

    StringColumn4: TStringColumn;

    StringColumn5: TStringColumn;

    Button3: TButton;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

 private

    { Private declarations }

 public

    { Public declarations }

 end;

var

 Form12: TForm12;

 

implementation

 

{$R *.fmx}

{修改表格的宽度和行高}

procedure TForm12.Button1Click(Sender: TObject);

begin

     StringGrid1.Width:= 500;

     StringGrid1.RowHeight := 18;

     TButton(Sender).Text := '宽与高';

end;

 procedure TForm12.Button2Click(Sender: TObject);

 {添加一行}

begin

     StringGrid1.RowCount := StringGrid1.RowCount + 1;

     TButton(Sender).Text:= '加一行';

end;

{添加一列:addItem}

{所有单元}    

procedure TForm12.Button3Click(Sender: TObject);

var

     c,r: Integer;

begin

     for c := 0 to StringGrid1.ColumnCount - 1 do

        for r := 0 to StringGrid1.RowCount - 1 do

             StringGrid1.Cells[c,r] := Format('列:%d,行:%d', [c,r]);

end;

 

end.

你可能感兴趣的:(String)