原文

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. .net asp 实现json 格式跨域访问 的方法

    在<configuration> 配置目录下添加允许跨域的头部信息 //webapi 默认的web.config有配置 //1)删除 下面参数 否者WEB API 会 出现405 错误 没 ...

  2. 锯齿状优惠券css绘制

    对于图上优惠券左右两侧的半圆锯齿效果,两种处理方式,一种直接使用切图进行处理,一种是纯css进行效果绘制.切图的就不再赘述,主要说纯css效果绘制 绘制的结果如下图: 难点在于两侧的半圆孔是透明色,不 ...

  3. xftp免费版使用

    转自https://www.jb51.net/softs/621774.html

  4. jquery promise (Deferred)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. vuex-getter

    store 的计算属性. getter 的返回值会根据它的依赖被缓存起来,且只有当它的依赖值发生了改变才会被重新计算 const store = new Vuex.Store({ state: { t ...

  6. Eclipse导入war包二次开发

    有实际项目在跑的war包,却没有源码,苦于想查看源码,身处运维组为研发组看不起,拿不到源码,只能自己来反编译了. 其实在解压war包后,可以看到文件夹中,已经存在了jsp文件,但是却没有逻辑代码层(a ...

  7. Building tools 为什么是主流?

    一.building tools 为什么主流? Gradle 是目前比较流行的构建工具之一,Android Studio 中集成的就是 Gradle,并针对 Android 应用开发了插件 Gradl ...

  8. wed

    先有一个无后缀的flag 文件 第一次改成 TXT 收索FLAG 得到了一段 flag.txt f返回到第一次修改后缀 改成RAR 打开RAR 发现一个 flag.txt 的文件 打开,即得到 fla ...

  9. 最短路,floyd算法,图的最短路径

    题目描述: 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线 ...

  10. 【oracle入门】数据模型

    数据模式也是一这种模型,它是数据库中用于提供信息表示的操作手段的形式架构,是数据库中用来对现实世界惊喜抽象的工具.数据模型按不同的应用层次分为3种类型,分别为概念数据模型.逻辑数据模型.物理数据模型. ...