原文

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. php 搜索附近人及SQL语句的写法

    /** * 根据经纬度和半径查询在此范围内的所有 * @param String $lat 纬度 * @param String $lng 经度 * @param float $radius 半径 * ...

  2. python学习(五)

  3. 『流畅的Python』第15章:上下文管理器和else块

  4. Matlab:高阶常微分三种边界条件的特殊解法(中心差分法,高精度导数边界处理)

    函数文件1: function b=F(f,x0,h,N) % b(1,1)=x0(1)-h*x0(2)-u(1); % b(2,1)=x0(2)+h*x0(1)^2-u(2)-h*f; b=zero ...

  5. js 数组的pop(),push(),shift(),unshift()方法小结

    关于数组的一些操作方法小结: pop(),push(),shift(),unshift()四个方法都可改变数组的内容以及长度: 1.pop() :删除数组的最后一个元素,并返回被删除的这个元素的值: ...

  6. javascript接口注释法

    //注释法//简单,功能弱 利用 大型的项目靠得是规范和标准 有充分时间 缺点:人为的遵守/** interface personDao{* function add(obj);* function ...

  7. 第十二次作业 - Beta答辩总结

    目录 前言 项目的链接与宣传 项目总结 原计划 达成情况 原因分析 [ Beta 冲刺博客链接汇总] [燃尽图] Beta版本展示 使用说明 视频展示 图片展示 答辩总结 [团队中个人的贡献比例] [ ...

  8. 第一章:深入web请求过程

    初学者,总结一下读书笔记,望海涵. 1.1 B/S网络架构概述 相比于C/S架构,B/S网络架构(Browser/Server)从前端到后端都得到了简化,都基于统一的应用层协议HTTP来交互数据,采用 ...

  9. return 返回值的用法

    #coding:utf-8 # (1)把数据返回到函数调用处 def func(): # return 1 # return "aaabb" return [1,2,3,4] re ...

  10. FCC JS基础算法题(2):Check for Palindromes(检查回文字符串)

    题目描述: 如果给定的字符串是回文,返回true,反之,返回false.如果一个字符串忽略标点符号.大小写和空格,正着读和反着读一模一样,那么这个字符串就是palindrome(回文).注意你需要去掉 ...