TTMSFMXGrid - initialize in-cell color picker

I have a TTMSFMXGrid with color pickers in certain cells descended from TTMSFMXColorPicker. I should like to initialize each color picker to a certain color when the form is created (rather than the selected color being null). How could I do that? Thank you.

Hi, 


You can use the following code to achieve this:

procedure TForm112.TMSFMXGrid1CellEditGetColor(Sender: TObject; ACol,
  ARow: Integer; CellEditor: TFmxObject; var CellColor: TAlphaColor);
begin
  if CellColor = claNull then
    CellColor := claRed
end;

Kind Regards, 
Pieter

Thank you, but that does not not achieve my objective because the OnCellEditGetColor event does not take place until the cell is being edited. I wanted the color to be initialized prior to any editing of the grid.

Hi, 


You can access the picker with TMSFMXGrid1.CellColorComboBox and then preset the color, yet the color will be reverted to claNull because the color is taken from the cell when editing.

Kind Regards, 
Pieter

I'm not sure I understood about the color picker taking its color from the cell. I have no trouble initializing the cell colors - please see image below for an example. The colors of the four cells were initalized in FormCreate but the color pickers remain at claNull as specified in their constructors. Obviously, I would like the color pickers to match the cell colors.


If it is not possible to initialize a color picker on a cell-by-cell basis, then I guess it's also not possible to save the color picker settings to file and reload them later? And the same limitation would apply to other in-cell editors such as trackbars? I had hoped that at a latter stage of my program development, I would be able to save and restore the grid complete with all in-cell control settings. Is that not possible?




Can you please send us a sample that demonstrates this so we can investigate this here ?

I'm sorry my questions are not clear. I'm sure there are several points that I'm not understanding very well. Please let me start with one simple scenario so I can try to learn one point at a time. With this objective, I have created a form with a TTMSFMXGrid and a TSpinBox to set the grid's RowCount. In one column, I set the editor type as etColorPicker in the Object inspector. In the next column, I set the editor type using the following code:


procedure TForm3.TMSFMXGrid1GetCellClass(Sender: TObject; ACol, ARow: Integer;
  var CellClassType: TFmxObjectClass);
begin
if (ACol = 2) and (ARow > 0) then
    CellClassType := TTMSFMXColorPicker;
end;

I run the program and set some colors (see image 1 below). I then add one row to the grid. Column 1, using etColorPicker, behaves nicely retaining its colors in the previously existing rows. However, Column 2  has its colors set back to claNull (see image 2 below) when the RowCount is changed. It would be very helpful to know why (and perhaps with a few such questions I will know how to use the grid in my application). Thanks a lot!




Hi, 


When overriding the cell class, you need to manually manage the cell, which means, in this case, you will need to keep track of the color for that cell. You can override the OnGetCellProperties event, where you can cast the cell that is passed as a parameter to the TTMSFMXColorPicker and then preset the color and assign the event that is triggered when selecting a color. You could use the TMSFMXGrid1.Colors property for this. If you need more help, you can prepare your sample, so we can investigate here and add the missing code.

Kind Regards, 
Pieter

Thank you, I figured it out from the clues you provided.