Post by How to find out, if the currently drawn cell in
TDBGrid::OnDrawDataCell()-event
is the active one, i.e. part of the row, which is marked with an arrow
'|>' in the left column?
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);
}
}
//---------------------------------------------------------------------------