3
votes

What can you do if you want different cell controls in the same column of a grid in FireMonkey. The cell control seems to belong to the column, but there are situations (like the property editor), where some rows need a checkbox while other rows need a combobox or an edit control.

Thanks in advance.

4

4 Answers

2
votes

Arnaud already linked to my article in his answer. The article covers the basics of grids, columns and cells. The following steps should get you up and running:

  • Create a style, add to it the controls you want to show (i.e. a TCheckbox, a TCombobox and a TEdit). Add these within a TLayout, and set each controls StyleName to something memorable.
  • In your cells ApplyStyle use FindStyleResource to extract the controls you added above using their StyleNames.
  • When the grid calls your cell's SetData method, you need to set the Visible property for each control so only the appropriate one is shown. If you can't determine this from the data passed in, add an event handler to the cell to get the data.
  • You'll need to sort out the keyboard handling, which gets pretty messy. If memory serves, you need to pass keys from the grid/cell to the control (or or is it trap movement keys from the controls and pass them to the grid? Sorry if I forget exact detail).

Sorry I can't give a more detailed answer, but covering this completely would take a whole series of blog posts.

5
votes

You'll find out the solution in this article, I guess.

Sample custom grid cell

You'll have to create a create a custom cell class.

1
votes

Use a style - set the cell style when you set the cell data - then us the onapplystyle event to do anything clever you require with the newly styled cell.

This way you can add what controls you need to the style and then access the controls (to set events etc) with the onapplystyle.

Hint - FindStyleResource is your friend here :-)

1
votes

I have also needed a property editor and looked for a way hosting different cell types in one column. Using different styles for each row may be a solution as suggested above, but since Firemonkey grid doesnt reserve any cell control for a specific row, each time the cell control would be shown on the row, the true style would be applied to it. This is not a big problem for a static property editor, however for a real grid which has got may rows and different cell types in each row a diferent strategy is needed. So I came up with a different solution, I considered cell type proxies between TColumn and cell controls, so that each cell proxy will reserve the cell controls that is responsible for. First of all, I have a new TColumn (TvariantColumn) which is responsible for the top strategy.

vColumn := TVariantColumn.Create(Self);
vColumn.Header := 'Variant Column';
vColumn.OnGetCellProxyIndex := GetCellProxyIndex;
Grid1.AddObject(vColumn);

Then create any proxies like

vColumn.NewCellProxy(TTextProxy); 
vColumn.NewCellProxy(TColorComboProxy);
vColumn.NewCellProxy(TComboColorProxy);

You can also handle Proxy specific jobs after you create it, like

with TProgressProxy(vColumn.NewCellProxy(TProgressProxy)) do //4
begin
  Min := 0;
  Max := 100;
end;

with  TPopUpProxy(vColumn.NewCellProxy(TPopupProxy)) do //5
begin
  Items.Add('Istanbul');
  Items.Add('Paris');
  Items.Add('NewYork');
end; 

I have blogged my method in my website and published a detailed article where you can find more about the subject.