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( ...
随机推荐
- test-overflow:ellipsis的应用----转载
关键字: text-overflow:ellipsis 语法:text-overflow : clip | ellipsis 取值: clip :默认值 .不显示省略标记(...),而是简单的裁切. ...
- python functiontools模块中的 wraps
直接上代码看效果: # 定义一个最简单的装饰器 def user_login_data(f): def wrapper(*args, **kwargs): return f(*args, **kwar ...
- MongoDB一键安装
#!/bin/bash export lang=Cecho '#1.关闭本地的MongoDB'#service mongodb stopecho '#2.清空本地MongoDB的安装文件'rm -rf ...
- mqtt------ mosca服务器端参数简介
一:服务器端 为什么使用mosca:mosca是基于node.js开发,上手难度相对较小,其次协议支持完整,除了不支持Qos 2,其它的基本都支持.持久化支持redis以及mongo.二次开发接口简单 ...
- 微信小程序城市定位(百度地图API)
概述 微信小程序提供一些API(地址)用于获取当前用户的地理位置等信息,但无论是wx.getLocation,还是wx.chooseLocation均没有单独的字段表示国家与城市信息,仅有经纬度信息. ...
- rest_framework 之视图
1. 继承ModelSerilizer,直接指定要序列化的表模型 MySerializers.py from app import models # 继承ModelSerilizer,直接指定要序列化 ...
- Android 音视频深入 八 小视频录制(附源码下载)
本篇项目地址,求starthttps://github.com/979451341/Audio-and-video-learning-materials/tree/master/%E5%B0%8F%E ...
- 用图片作为label,for属性IE下不起作用
IE浏览器存在一个BUG,当你使用label的for属性达到点击label使对应的表单元素聚焦,label中的内容为图片时,IE浏览器下不起作用. 例如: <input type="c ...
- jvm-垃圾收集
概述 说起垃圾收集,大部分人都把这项技术当做Java语言的伴生产物.其实,GC主要就是考虑完成三件事情: 哪些内存需要回收 什么时候回收 如何回收. 经过半个多世纪的发展,目前内存的动态分配与内存的回 ...
- 2.5 定义FTP工具的各种方法
用class定义ftp工具的各种方法 import os,sys from ftplib import FTP from mimetypes import guess_type,add_type fr ...