TDBGrid::OnDrawDataCell()-event
is the active one, i.e. part of the row, which is marked with an arrow
'|>' in the left column?
I want to change the color of these cells slightly to make it more
readable...
Thanks,
Michael
According to BDS and CB2007 docs,
"Do not write an OnDrawDataCell event handler. OnDrawDataCell is obsolete
and included for backward compatibility. Instead, write an OnDrawColumnCell
event handler."
If you use OnDrawColumnCell, check the State parameter.
I use the following code for the OnDrawColumnCell handler (gives a nice
effect if you choose the right colors...):
//---------------------------------------------------------------------------
class TExposedDBGrid : public TDBGrid
{
public:
__property FixedRows;
__property Row;
__property DataLink;
};
//---------------------------------------------------------------------------
void __fastcall TfrmMain::DrawColumnCellHandler(TObject *Sender,
const TRect &Rect, int DataCol, TColumn *Column, TGridDrawState State)
{
TExposedDBGrid* grd = static_cast<TExposedDBGrid*>(Sender);
grd->Canvas->Font->Style = TFontStyles();
if(grd->SelectedRows->CurrentRowSelected)
{
grd->Canvas->Brush->Color = customSelectedColor;
grd->Canvas->Font->Color = clWindowText;
}
else
{
if(grd->DataLink->ActiveRecord == (grd->Row - grd->FixedRows))
{
grd->Canvas->Brush->Color = customHighlightColor;
grd->Canvas->Font->Color = clWindowText;
}
else
{
grd->Canvas->Brush->Color = grd->Color;
grd->Canvas->Font->Color = clWindowText;
}
}
grd->DefaultDrawColumnCell(Rect, DataCol, Column, State);
if(State.Contains(gdSelected))
{
grd->Canvas->Brush->Color = (ActiveControl == grd) ? clHighlight :
clWindowText;
grd->Canvas->FrameRect(Rect);
}
}
//---------------------------------------------------------------------------
I replaced my OnDrawDataCell-function and used especially the line
if(grd->DataLink->ActiveRecord == (grd->Row - grd->FixedRows)) ...
for deciding if the currently displayed cell is part of the current
record....
Now it's working fine.
Thank you,
Michael