原文

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的更多相关文章

  1. [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 ...

  2. EXTJS 4.2 资料 控件之Grid Columns 列renderer 绑定事件

    columns: [ { header: '序号', xtype: 'rownumberer', align: 'center', width: 100 }, { header: 'CompanyId ...

  3. Oracle Grid Infrastructure Installation Guide for Linux 以debug模式安装并记录日志

    最新文章:Virson's Blog 使用如下命令能够以debug模式安装Oracle Grid并将日志记录到文件 [grid@vdb1 11ggrid]$ ./runInstaller -debug ...

  4. 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 ...

  5. [4]Telerik Grid 简单使用方法

    1.columns <% Html.Telerik().Grid(Model) .Name("Orders") .Columns(columns => { //绑定列名 ...

  6. ExtJS Grid导出excel文件

    ExtJS Grid导出excel文件, 需下载POI:链接:http://pan.baidu.com/s/1i3lkPhF 密码:rqbg 1.将Grid表格数据连同表格列名传到后台 2.后台导出e ...

  7. ExtJs 学习之开篇(三)Ext.grid.Panel表格中的处理

    Ext.grid.Panel Ext.create('Ext.grid.Panel',{        title:'测试表格',        width:400,        height:20 ...

  8. 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 ...

  9. 打印grid

    void PrintButtonClick(object sender, EventArgs e) { PrintPreviewDialog dlg = new PrintPreviewDialog( ...

随机推荐

  1. ES6 4个方法

    var string = 'Yo' string.startsWith('Y')        -> true      startsWith()查找字符串是否是以某一个字段开始的 string ...

  2. 『PyTorch』第十五弹_torch.nn.Module的属性设置&查询

    一.背景知识 python中两个属相相关方法 result = obj.name 会调用builtin函数getattr(obj,'name')查找对应属性,如果没有name属性则调用obj.__ge ...

  3. spring cloud(一)带你进入分布式

    spring cloud是近年来比较火的热门话题,很多大型公司也渐渐转型使用spring cloud来完善各种开发模式,我认为主要是由spring团队开发由来,致使会有那么多的使用者,在java的领域 ...

  4. php同curl post 发送json并返回json数据实例

    <?php $arr = array( 'subject'=>'课程', 'loginName'=>'Durriya', 'password'=>'123' ); //json ...

  5. js实现下雪雪花特效

    两种下雪特效: 1. <script type="text/javascript"> (function($){ $.fn.snow = function(option ...

  6. 菜鸟脱壳之脱壳的基础知识(三)——寻找OEP

    这节我们来讲讲如何寻找一个程序的OEP,即Original Entry Point.一些PE加壳程序在被加密的程序上面加了一个区段(有的壳也会合并区段),当外壳代码执行完毕以后,会跳到程序的本身的代码 ...

  7. mst总结

     1.jsonp跨域 Jsop的原理:利用script不存在跨域的问题,动态创建script标签,把需要请求的数据源地址赋值给其src属性,并且指定一个回调函数,从而接受到我们想要的数据 后台设置下 ...

  8. 2015-10-13 jQuery5实例

    jQuery(5)   一.扑克牌切换 <body> <div class="ig ig1"><img src="image/1.jpg&q ...

  9. 【ANT】输入中文格式为乱码

    使用ant编译,打出的日志的格式为乱码,加上下面的指定编码后,输出为中文了. 为方便拷贝,将其贴出来 <jvmarg value="-Dfile.encoding=UTF-8" ...

  10. linux c++ curl https 请求并双向验证SSL证书

    1.配置curl https请求需要提供 CA证书.客户端证书和客户端秘钥,这三个文件的pem格式. 分别对应 curl_easy_setopt() 函数的 下面三个参数: CURLOPT_CAINF ...