Search code examples
delphigriddelphi-xe2firemonkey

FireMonkey grid with different controls in same column


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.


Solution

  • 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.