Delphi XE2 之 FireMonkey 入門(43) – 控制項基礎: TStringGrid、TGrid

來源:互聯網
上載者:User
TStringGrid、TGrid 都是從 TCustomGrid 繼承; 區別有:
1、它們的列對象分別是: TStringColumn、TColumn;
2、TStringGrid 比 TGrid 多出了 Cells[] 屬性.

因為 TGrid 沒有 Cells[] 屬性, 暫時不方便使用; 我嘗試取其當前單元值時竟然用了這樣的代碼:
(Grid1.Columns[Grid1.ColumnIndex].CellControlByRow(Grid1.Selected) as TTextCell).Text

TStringGrid 測試:

{ 設計時放好 StringGrid1, 運行時填充資料 }procedure TForm1.FormCreate(Sender: TObject);var  i,c,r: Integer;begin  StringGrid1.AlternatingRowBackground := True;  StringGrid1.UseSmallScrollBars := True;  for i := 0 to 5 do //從設計時添加列比這方便  begin    with TStringColumn.Create(Self) do    begin      Parent := StringGrid1;      Width := StringGrid1.ClientWidth / 6;    end;  end;  StringGrid1.RowCount := 20;  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;{ 取當前單元值 }procedure TForm1.Button1Click(Sender: TObject);begin  ShowMessage(StringGrid1.Cells[StringGrid1.ColumnIndex, StringGrid1.Selected]);end;
成員概覽:
{ TCustomGrid }public  constructor Create(...); override;        //  destructor Destroy; override;             //  function ColumnByIndex(...): TColumn;     //根據索引擷取列對象  function ColumnByPoint(...): TColumn;     //根據位置擷取列對象  function RowByPoint(...): Integer;        //根據位置擷取行號  procedure AddObject(...); override;       //  property TopRow: Integer ...;             //擷取可見的首行的行號  property VisibleRows: Integer ...;        //擷取可見的行總數  property ColumnCount: Integer ...;        //列數(也是唯讀)  property ColumnIndex: Integer ...;        //擷取或設定列索引  property Columns[Index: Integer]: TColumn ...; //以數組索引的方式擷取列對象  property RowCount: Integer ...;           //行數(可讀寫)  property Selected: Integer ...;           //當前行號  property OnGetValue: TOnGetValue ...;     //取值時  property OnSetValue: TOnSetValue ...;     //賦值時published  property StyleLookup;                     //  property AlternatingRowBackground: Boolean ...; //是否使用交替背景; 預設 False  property CanFocus default True;           //  property DisableFocusEffect default True; //是否取消焦點特效  property RowHeight: Single ...;           //行高  property ShowSelectedCell: Boolean ...;   //是否呈現單元選擇效果; 預設 True  property ShowVertLines: Boolean ...;      //是否顯示豎格線  property ShowHorzLines: Boolean ...;      //是否顯示橫格線  property ShowHeader: Boolean ...;         //是否顯示表格頭  property ReadOnly: Boolean ...;           //是否唯讀; 預設 False  property TabOrder;                        //  property OnEdititingDone: TOnEdititingDone ...; //輸入時end;{ TGrid }TGrid = class(TCustomGrid)published  property RowCount;   //  property OnGetValue; //  property OnSetValue; //end;{ TStringGrid }public  property Cells[ACol, ARow: Integer]: string ...; //published  property RowCount;   //end;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.