Page 1 of 1

getting cell color in a TCRDBGrid

Posted: Wed 20 Apr 2011 12:38
by albourgz
Hello,

using bcb 2010 / odac 6.90.0.57.
I have a function receiving as parameter a TCRDBGrid, and exporting its content to an excel spreadsheet, works fine.
The cells in the dbgrid have different colors, using the OnDrawColumnCell event.
I would like these colors also to be set in the excel spreadsheet.
I tried setting grid->Col and grid->Row, then using grid->Brush->Color and grid->Canvas->Font->Color to get cell current color, but it doesn't work.

=>Is there a way to know the color of a cell in a T(CR)DBGrid?

Regards.

Posted: Thu 21 Apr 2011 12:04
by AlexP
Hello,

Background and font colors should be defined only in the onDrawColumnCell event.
But to determine cells colors, you can use the same algorithm as for color assignment.

not very usable in practise

Posted: Fri 22 Apr 2011 07:41
by albourgz
I have an app with 100's of grids, all inherited from same form, with an onKeyPress allowing an export to excel, but each form has different DrawColumnCell implementation.

My function receives a grid as param, so I should use
grid->InDrawColumnCell(....) for each cell, then read color properties, but I have to be able to give a rect and a state, it seems difficult. Furthermore, the grid is on screen so I would have to prevent the method to be called when displaying the grid.

Does someone have a better method or know another (inherited) component abel to give this information?
Is this information available in the bcb XE version of TDBGrid?

Regards.

Posted: Tue 26 Apr 2011 06:45
by AlexP
Hello,

Our TCRDBgrid (as standard TDBGrid) doesn't save color properties, so yo should manually save them for each DBGrid.
For example, you can create your own DBGrid successor of TcustomDBGrid with the needed functionality.