原文
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.
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.
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:
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));
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
原文:http://www.cnblogs.com/key-ok/p/3531925.html