Custom Grid Columns - FireMonkey Guide
原文
http://monkeystyler.com/guide/Custom-Grid-Columns
ack to FireMonkey Topics
As we saw in TGrid a FireMonkey grid consists of columns which contain cells made of any descendant of TStyledControl. Or, effectively, any control. A number of column types come built in but it is a pretty simple matter to create your own. Here we’ll create a column of TColorComboBoxes.
Cells
Firstly you’ll need a class to use for the cells, which we’ll call TColorComboCell.
type TColorComboCell = class(TColorComboBox) end;
You could just use the base class (TColorComboBox) directly but creating an explicit class for the cells adds benefits such as the ability to change styles more easily (just create a style called ColorComboCellStyle) and we can more easily modify behavious needed specific to a grid cell.
If you’re creating your own control from scratch to use as a cell you’ll need to implement GetData and SetData methods of TStyledControl since these are used by the grid for reading and writing data to the cell.
The Column
Now we need a custom column class which we’ll call TColorComboColumn. In the column class we need to override the CreateCellControl function which creates individual cells.
function TColorComboColumn.CreateCellControl: TStyledControl; begin Result := TColorComboCell.Create(Self); TColorComboBox(Result).OnChange := DoTextChanged; end;
Three things to note here:
- We don’t need to set Parent, this will be set by the column.
- If your cell wants to pass data back to your application you’ll need to hook into the cell’s OnChange or similar event so the grid will fire it’s OnSetValue and OnEditingDone events. If the name of the method I’m hooking up sounds inappropriate it’s down to the slightly oddball class hierarchy of columns where TColumn, for string data, acts as the base class for all column classes, rather than using an abstract class.
- There’s no need to call the inherited method. Indeed, you positively don’t want to since doing so will leave you with an unwanted TTextCell. I apologise if this seems messy, but again it’s all down to that strange class heirarchy.
Round Up
And that’s really all there is to it. You can now add your column to a grid with the line
Grid1.AddObject(TColorComboColumn.Create(Grid1));
Full Source
unit ColorComboColumn;
interface uses FMX.Colors, FMX.Grid, FMX.Controls;
type TColorComboCell = class(TColorComboBox) end;
type TColorComboColumn = class(TColumn) protected function CreateCellControl: TStyledControl;override; end;
implementation
{ TColorComboColumn }
function TColorComboColumn.CreateCellControl: TStyledControl; begin Result := TColorComboCell.Create(Self); TColorComboBox(Result).OnChange := DoTextChanged; end;
end.
Custom Grid Columns - FireMonkey Guide的更多相关文章
- [CSS] Specify grid columns, rows, and areas at once with the grid-template shorthand
We can specify grid columns, rows, and areas in one property using the grid-template shorthand. .con ...
- EXTJS 4.2 资料 控件之Grid Columns 列renderer 绑定事件
columns: [ { header: '序号', xtype: 'rownumberer', align: 'center', width: 100 }, { header: 'CompanyId ...
- Oracle Grid Infrastructure Installation Guide for Linux 以debug模式安装并记录日志
最新文章:Virson's Blog 使用如下命令能够以debug模式安装Oracle Grid并将日志记录到文件 [grid@vdb1 11ggrid]$ ./runInstaller -debug ...
- Visualizing mathematical functions by generating custom meshes using FireMonkey(很美)
Abstract: This article discusses how you can generate your own 3-dimensional mesh for visualizing ma ...
- [4]Telerik Grid 简单使用方法
1.columns <% Html.Telerik().Grid(Model) .Name("Orders") .Columns(columns => { //绑定列名 ...
- ExtJS Grid导出excel文件
ExtJS Grid导出excel文件, 需下载POI:链接:http://pan.baidu.com/s/1i3lkPhF 密码:rqbg 1.将Grid表格数据连同表格列名传到后台 2.后台导出e ...
- ExtJs 学习之开篇(三)Ext.grid.Panel表格中的处理
Ext.grid.Panel Ext.create('Ext.grid.Panel',{ title:'测试表格', width:400, height:20 ...
- Grid Infrastructure Single Client Access Name (SCAN) Explained (文档 ID 887522.1)
APPLIES TO: Oracle Database - Enterprise Edition - Version 11.2.0.1 and laterExalogic Elastic Cloud ...
- 打印grid
void PrintButtonClick(object sender, EventArgs e) { PrintPreviewDialog dlg = new PrintPreviewDialog( ...
随机推荐
- SpringBoot mybatis配置
首先pom.xml <!-- mybatis 配置 --> <dependency> <groupId>org.mybatis.spring.boot</gr ...
- 数字类型转换 --Python3
数值运算符可以隐式转换输出结果的数字类型,另外,Python内置的数字类型转换函数可以显示地在数字类型之间转换: 函数 描述 int(x) 将x转换为整数,x可以是浮点数和字符串类型 float(x) ...
- Redis缓存设计及常见问题
Redis缓存设计及常见问题 缓存能够有效地加速应用的读写速度,同时也可以降低后端负载,对日常应用的开发至关重要.下面会介绍缓存使 用技巧和设计方案,包含如下内容:缓存的收益和成本分析.缓存更新策略的 ...
- ELK安装使用教程
一.说明 ELK是当下流行的日志监控系统.ELK是Elasticsearch.Logstash.Kibana三个软件的统称. 在ELK日志监控系统中,Logstash负责读取和结构化各类日志+发送给E ...
- 码云git使用五(创建远程分支和更新远程分支)
1.创建一个与远程分支没有关联的本地分支 2.从远程拉取到本地分支 3.创建远程分支() 4.搞定了.
- myhome vscode plugins
├─ 1194979849.code-snippets-0.1.18├─ adamwalzer.string-converter-0.1.1├─ alefragnani.bookmarks-9.3.0 ...
- 数据分析---SQL(Access数据库)
1. SQL(Structure Quest Language) 一种结构化查询语言,它是一种通用的关系型数据库操作语言,用于存取数据,查询,更新和管理数据库. 2. 基本语句 Select, Cre ...
- 修改C#mvc的默认首页
找到Global.asax,在其中RouteConfig.RegisterRoutes(RouteTable.Routes);这条方法上,右键转到定义,在defaults: new { control ...
- Mad Libs游戏:熟悉python编程环境,基本输入输出
Mad Libs游戏: 代码: name1=input("请输入一个名字:") name2=input("请输入一个名字:") print("{}才刚 ...
- Eclipse ee项目 Java Resources文件报错解决方法
通常是JDK版本配置问题,这里使用的是JDK1.8版本 确保jre版本为本机配置的版本 打开Navigator目录的.settings文件夹修改org.eclipse.wst.common.compo ...