Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-04-2003, 05:59 AM
rao2001 rao2001 is offline
Senior Member
 
Join Date: Jun 2001
Posts: 214
Default Selected cell color in DBGRID...

How can I change the selected cell color in a DBGRID?

Rogério Alves de Oliveira - Jundiai - SP - Brasil
[i]rogerioaoliveira@ig.com.br[i]
Reply With Quote
  #2  
Old 04-04-2003, 06:16 AM
nikolayj nikolayj is offline
Senior Member
 
Join Date: May 2002
Posts: 335
Default RE: Selected cell color in DBGRID...

Hi, how about this:
-------------------------------------------------<cb>
procedure TForm1.FormCreate(Sender: TObject);
begin
DBGrid1.DefaultDrawing := False;
end;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with DBGrid1.Canvas do begin
if State = [gdSelected, gdFocused] then begin
Brush.Color := clRed;
Font.Color := clWhite;
end else begin
Brush.Color := clWhite;
Font.Color := clRed;
end;
FillRect( Rect );
TextOut( Rect.Left, Rect.Top, Column.Field.Text );
end;
end;
</cb>-------------------------------------------------

<cr> Click Accept if helped
Reply With Quote
  #3  
Old 04-04-2003, 06:16 AM
Eddy-B Eddy-B is offline
Senior Member
 
Join Date: Feb 2002
Posts: 1,467
Default RE: Selected cell color in DBGRID...

you cannot effectively change that color, as it is determined by the color scheme of the user (using windows default, it would always be clNavy).

What you can do, is create an OnDrawCell event:

when <cb>State</cb> contains gdSelected or gdFocused, redraw the cell, using your own background color.

regards,

Eddy-B

Please click <cr>Accept as answer</cr> if this helped</cr>
Reply With Quote
  #4  
Old 04-04-2003, 07:17 AM
Sylvestre Sylvestre is offline
Senior Member
 
Join Date: Mar 2003
Posts: 116
Default RE: Selected cell color in DBGRID...

Try this :

with Sender as TDBGrid do
if Columns[0].Field.AsString = SomeThing
begin
if gdSelected in State then
Canvas.Brush.Color := clHighlight //---- Selected
else
Canvas.Brush.Color := clYellow; //---- Other

//---- Default
DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;


Sylvestre
Reply With Quote
  #5  
Old 04-04-2003, 08:15 AM
rao2001 rao2001 is offline
Senior Member
 
Join Date: Jun 2001
Posts: 214
Default RE: Selected cell color in DBGRID...

Using the same teory I'm trying to give another color to my selected lines in DBGRID... not only my focus cell!!!

Do you know how?

Rogério Alves de Oliveira - Jundiai - SP - Brasil
[i]rogerioaoliveira@ig.com.br[i]
Reply With Quote
  #6  
Old 04-04-2003, 09:35 AM
Eddy-B Eddy-B is offline
Senior Member
 
Join Date: Feb 2002
Posts: 1,467
Default RE: Selected cell color in DBGRID...

same answer; check for NOT focused or selected:
(using source code from Nikolayj)

<cb><tt>
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with DBGrid1.Canvas do begin
if State = [gdSelected, gdFocused] then begin
Brush.Color := clRed;
Font.Color := clWhite;
end else begin
<cr>// here it is:</cr>
Brush.Color := clWhite;
Font.Color := clRed;
end;
FillRect( Rect );
TextOut( Rect.Left, Rect.Top, Column.Field.Text );
end;
end;
</cb></tt>

Eddy-B

Please click <cr>Accept as answer</cr> if this helped</cr>
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:19 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2014, vBulletin Solutions, Inc.