Grid ColorPicker -> permanent color, without seeing to Color value

Hello,

There is a grid where the user can create labels and choose color for each label.
There are two fields: LabelName and LabelColor.

I can think of two scenarios, but neither of these work:

I show both LabelName and LabelColor fields. The LabelColor column's Editor is set to colorPicker:

Grid.Columns[1].Editor := getColorPicker;
Grid.Columns[1].AddSetting(gcsEditor);

With this version the user can set a color by editing for that moment , but when he clicks on the next row, the ugly color value can be seen e.g. -13383452

  1. I only show the LabelName . The column's Editor is set to colorPicker, but when the user sets the color, the color value is set to LabelColor field.
    I don't know how to use this.

Can you please help me?
Thank you!

Hi,

When selecting a getColorPicker at designtime, the editor target changes automatically to the fill color of the cell

In this case, the value is not set to the cell content but to the cell layout fill

  TMSFNCDataGrid1.Columns[1].Editor := getColorPicker;
  TMSFNCDataGrid1.Columns[1].AddSetting(gcsEditor);
  TMSFNCDataGrid1.Columns[1].EditorTarget := getFillColor;
  TMSFNCDataGrid1.Columns[1].AddSetting(gcsEditorTarget);

Colors can be retrieved or set via

TMSFNCDataGrid1.Colors[1, 5] := gcFuchsia;

Alternatively, if you want to keep the color and not display the text, use

procedure TForm1.TMSFNCDataGrid1BeforeDrawCell(Sender: TObject;
  AGraphics: TTMSFNCGraphics; ACell: TTMSFNCDataGridCell;
  var ACanDraw: Boolean);
begin
  ACell.DrawElements := ACell.DrawElements - [gcdText];
end;

Let me know if this is what you are looking for?

Hello,

Thank you for the answer. With your help I used :

Grid.Columns[2].Editor := getColorPicker;
Grid.Columns[2].AddSetting(gcsEditor);
Grid.Columns[2].EditorTarget := getFillColor;
Grid.Columns[2].AddSetting(gcsEditorTarget);

procedure TMainForm.GridBeforeDrawCell(Sender: TObject;
AGraphics: TTMSFNCGraphics; ACell: TTMSFNCDataGridCell;
var ACanDraw: Boolean);
begin
If ACell.Row = 0 Then Exit;

If ACell.Column = 2 Then
Begin
ACell.DrawElements := ACell.DrawElements - [gcdText];
End;

end;

And when I started the program, it worked how I expected: I could choose the color with the Color Picker and then in the cell I could see only the color.

However when I quit the program and started it again, the previously colored records were "colorless", although in the database field the color codes were there.

So it seems the coloring works only for the freshly colored cells for that very session. How can I make this permanent?

Thank you!

I wasn't aware you were binding to a dataset. There are several ways to bind to a cell, by default the adapter only picks up the cell value. Since the color picker actually binds to the fill color, it's not picked up. You might need to change tactics. Attached is a sample demonstrating how to bind the color to the cell value instead and change the fill color of the cell dynamically based on the cell value.

Sample.zip (19.5 KB)

Hi Pieter,

Thank you very much for the sample. It works well.
Only there is a minor thing, which might confuse the user : if he clicks in a color cell, instead of not changing the cell color, it changes to the default cell coloring (have a look at the attached video).

The best thing would be to invoke the color editor immediately when the user clicks on the color cell.
Can this be done? Thank you very much!

Hi, there is an option to directly start editing

TMSFNCDataGrid1.Options.Mouse.DirectEdit := True;