Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find out, if the currently drawn cell in TDBGrid::OnDrawDataCell()-event is the active one?

3 views
Skip to first unread message

MR

unread,
Jul 30, 2007, 3:23:46 AM7/30/07
to
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?

I want to change the color of these cells slightly to make it more
readable...


Thanks,

Michael

Mark Guerrieri

unread,
Jul 30, 2007, 4:45:44 PM7/30/07
to
> 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);
}
}
//---------------------------------------------------------------------------


MR

unread,
Jul 31, 2007, 4:29:41 AM7/31/07
to
Thanks a lot:

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

0 new messages