Cell Color issues an ColorPicker

I am populating the grid with colour values as text and using OnDrawCell to set the background of a cell. It seems the OnDrawCell event is overwriting the contents of the cell.  Am I using the wrong approach to colour the background of a cell.  

I also want to be able to set the Font colour of individual cells so the font is always visible regardless of background colour.  I haven't found a way to set the fontcolor of individual cells.

Finally, I cannot set the ColorPickerDropDown.SelectedColor to reflect the background colour of the cell.  I have tried using StringToColor of the text value of the cell but that doesn't set the SelectedColor in the dropdown.

OnGetCellProp is the event to use to customize the cell background color by modifying the ABrush.Color parameter. There is no need to perform custom drawing for this.

You can also set the font color via OnGetCellColor and modifying AFont.Color.
Set the selected item in the TAdvColorPickerDropDown via TAdvColorPickerDropDown.ItemIndex

Looking at the Object inspector for ADVStringGrid I don't see an OnGetCellProp, I can see OnGetCellColor, OnGetBorderColor and GetCelBorderProp but no OnGetCellProp.  This is with v8.8.3.0.

Sorry, I confused with another component. I meant to use OnGetCellColor

Is there no way to set the ColorPIckerDropDown selected colour byTColor rather than itemindex?  All I want to do is to set the ColorPickerDropDown to the colour of the Brush.Color of the cell it is editing.  


At present I establish the index by running through the ColorPicker.Colors.Items until I find a match.  However, setting the ColorPickerDropDown itemindex to the matched index fails to set the dropdown to the required colour, it simply defaults to clWhite.

I have tried setting the ColorPickDropDown Itemindex in both GetEditorProp and GeteditorType. 

It is such an obvious thing that I cannot believe there isn't a simple solution.

I do not understand why you have an issue with this. The ColorPickerDropDown automatically picks up its color from the cell color, so there should be no code to add.
If you want to override the color with which the editor starts editing, set grid.Colors[acol,arow] := YourColor from the OnGetEditorProp event handler.

I have stripped out the code for setting the ColorPicker Index.

When I first bring up the form and click on a cell to edit the drop down doesn't appear immediately but does on second click.  It defaults to white, if I then choose the correct cell colour it works as you would expect sets the colour of the cell and on returning to that cell it will pick up the correct colour..

The behavior you describe is by design.
When you want that the cell editor opens on the first click, set grid.MouseActions.DirectEdit = true

I have done that now, it drop s down immediately but it is still defaulting to clWhite when the cell is in cat clNavy.


Do you set the cell default color with grid.Colors[col,row]:TColor

No, should I?

I'm not sure  how else you expect it to pick up clNavy as the default cell color is clWhite.

I have already loaded the cell colours into the grid from the registry on the getCellColor event, I just want it to pick up the colour which is already there.  Do I have to set grid.colors[row,Col] as well?

Just grid.colors[Col,Row] should be sufficient.

Thanks for all your help... I now have it doing what I want.  I have removed setting the Brush colour in GetCellColor and now only set the font colour so that it contrasts with the back colour.  Setting the colors[Col,Row] works perfectly.


I now have a couple of questions on ADVMemo but I  will post those on the general forum.