DBGrid and edColorPickerDropDown

Hi,


I am trying to set a column in a DBGrid to edColorPickerDropDown at runtime. My code looks like

for (int i=0; i < QueryGrid->Columns->Count; i++) {
  TDBGridColumnItem* column = QueryGrid->Columns->Items;
  if (column->FieldName == "GRID_COLOR") {
    column->Editor = edColorPickerDropDown;
  } else 
  ...
}

The column displays the integer representation of the color. If I go into edit mode, the I see the color selector but the wrong color is selected. Also, if I leave the cell after editing, the number is displayed and the background color for the cell is set to the color I selected.

What's the best way to suppress displayed the number representation of the color? And how do I get the correct color to display on initial grid load?

Thanks

Have you tried implementing the grid.OnGetCellColor event and set the ABrush.Color parameter to the color value in the column from its number representation?

Ok. I added the following:


void __fastcall TEditWorkorderTypesDialog::QueryGridGetCellColor(TObject *Sender, int ARow, int ACol, TGridDrawState AState, TBrush *ABrush, TFont *AFont) {
  if (ARow == 0)
    return;
  if (QueryGrid->Columns->Items[ACol]->FieldName == "GRID_COLOR") {
    TColor c = QueryGrid->Cells[ACol][ARow].ToIntDef(0);
    ABrush->Color = c;
    AFont->Color = c;
  }
}

That hides the text and the background for the cell shows up as the right color.

Now, when I click in the cell, though, the background color goes away and I see the color number again.

Also, is there a way to control the number of colors in the dropdown? I would like more than the standard 16 or so colors

Thanks
  1. You can use grid.OnGetDisplText() to completely suppress the text
    2) You can choose other colorpicker styles via grid.ColorPickerDropDown.ColorSelectionStyle.  Via grid.ColorPickerDropDown you can actually full customize the color picker.