BDGrid row background color

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

BDGrid row background color

Postby giorgiom » Wed Mar 23, 2005 12:17 pm

Hi list.
I've got a DBGrid with 8 fields.
Entering in edit mode(dgEditing=true) on a field, i need to change the background color of the entire row.
Thanks.
Giorgio
giorgiom
 

Postby Damon » Thu Mar 24, 2005 4:41 am

Hi,
Try using the OnDrawColumnCell event to render the current row in a different color...

http://tinyurl.com/57gzp

Good luck,
Damon
Damon Chandler
Editor-in-Chief
C++Builder Developer's Journal
http://bcbjournal.com
User avatar
Damon
BCBJ Editor and Admin
BCBJ Editor and Admin
 
Posts: 285
Joined: Wed May 26, 2004 11:25 pm
Location: Stillwater, OK, USA

Postby giorgiom » Fri Mar 25, 2005 5:13 am

Thank you Damon.
The problem in i'd like that the background color of the cell in Edit mode
i'm writing on is a custom one.
I tried with setting DBGrid's DefultDrawing property to false and:

void __fastcall Twinlog::grigliaDrawColumnCell(TObject *Sender,
const TRect &Rect, int DataCol, TColumn *Column,
TGridDrawState State)
{
...
...
...
if(griglia->Options.Contains(dgEditing) && State.Contains(gdSelected))
{
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
griglia->Canvas->Brush->Color=clGreen;
griglia->Canvas->FillRect(Rect);
griglia->Canvas->TextOut(Rect.left+2,Rect.top+2,
Column->Field->AsString);
}
else
griglia->DefaultDrawColumnCell(Rect,DataCol,Column,State);
}

this way, i get the wanted background color clGreen, but as i start
typing on the cell the background color changes to white.
That is i want the clGreen color mantained during the typing.
Thanks a million.
Giorgio
giorgiom
 

Postby Damon » Fri Mar 25, 2005 3:33 pm

Giorgio,

You're seeing a white background during editing because the DBGrid displays its "inline editor," which is a small edit control that's placed over the cell during editing. You'll need to modify the color of this inline editor. Have a look at the following article...

http://bcbjournal.com/get_doc.php?art=subscribers/articles/vol6/0206/Even_more_string_grids__part_II.htm

The article is about TStringGrid controls, but I'm fairly certain that a very similar technique applies to DBGrids as well.

HTH,
Damon
Damon Chandler
Editor-in-Chief
C++Builder Developer's Journal
http://bcbjournal.com
User avatar
Damon
BCBJ Editor and Admin
BCBJ Editor and Admin
 
Posts: 285
Joined: Wed May 26, 2004 11:25 pm
Location: Stillwater, OK, USA


Return to Technical

Who is online

Users browsing this forum: Bing [Bot] and 22 guests