Delphi XE2 之 FireMonkey 入门(43) - 控件基础: TStringGrid、TGrid
2013-09-30 11:07
471 查看
Delphi XE2 之 FireMonkey 入门(43) - 控件基础: TStringGrid、TGrid
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;
相关文章推荐
- Delphi XE2 之 FireMonkey 入门(42) - 控件基础: TComboBox、TComboEdit
- Delphi XE2 之 FireMonkey 入门(41) - 控件基础: TListBox
- Delphi XE2 之 FireMonkey 入门(40) - 控件基础: TMemo
- Delphi XE2 之 FireMonkey 入门(39) - 控件基础: TScrollBox、TVertScrollBox、TFramedScrollBox、TFramedVertScrollBox
- Delphi XE2 之 FireMonkey 入门(38) - 控件基础: TPopupMenu、TMenuItem、TMenuBar、TMainMenu
- Delphi XE2 之 FireMonkey 入门(37) - 控件基础: TControl 概览
- Delphi XE2 之 FireMonkey 入门(36) - 控件基础: TForm
- Delphi XE2 之 FireMonkey 入门(32) - 数据绑定: TBindingsList: TBindList、TBindPosition [未完成...]
- Delphi XE2 之 FireMonkey 入门(31) - 数据绑定: 绑定数据库
- Delphi XE2 之 FireMonkey 入门(30) - 数据绑定: TBindingsList: TBindExpression 的 OnAssigningValue 事件
- Delphi XE2 之 FireMonkey 入门(28) - 数据绑定: TBindingsList: 表达式函数测试: SelectedText()、CheckedState()
- Delphi XE2 之 FireMonkey 入门(27) - 数据绑定: TBindingsList: TBindScope
- Delphi XE2 之 FireMonkey 入门(26) - 数据绑定: TBindingsList: TBindExprItems
- Delphi XE5 for Android (一)
- Delphi XE2 之 FireMonkey 入门(25) - 数据绑定: TBindingsList: 表达式的灵活性及表达式函数
- Delphi XE2 之 FireMonkey 入门(24) - 数据绑定: TBindingsList: TBindExpression.Direction
- Delphi XE2 之 FireMonkey 入门(23) - 数据绑定: TBindingsList: TBindExpression
- Delphi XE2 之 FireMonkey 入门(22) - 数据绑定: BindingSource、BindingName、FindBinding()、Binding[]
- Delphi XE2 之 FireMonkey 入门(21) - 和 FMX 相关的类(表)
- Delphi XE2 之 FireMonkey 入门(20) - TStyleBook(皮肤、样式相关)