Delphi Pages Forums  

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

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2001, 04:54 PM
guqi guqi is offline
Member
 
Join Date: Jan 2001
Posts: 98
Default How to control color in dbgrid?

I have a field name checked,it has two value one is yes,the other is no ,I want to yes display in dbgrid is red ,and no is blue ,how can I do this in dbgrid?
thank you.
Reply With Quote
  #2  
Old 03-14-2001, 06:31 PM
Tavares Tavares is offline
Senior Member
 
Join Date: Feb 2001
Posts: 1,318
Default RE: How to control color in dbgrid?

Hi!
The DefaultDrawing property of the DBGrid determines if the cell is painted and the item it
contains is drawn automatically. If True, the default drawing occurs. If False, your application
must handle all the drawing details in the OnDrawCell event handler, or in the
OnDrawDataCell event handler for the data grid. In this example, you will set the
DefaultDrawing property to False and specify the code within the OnDrawDataCell event.

The OnDrawDataCell event occurs whenever the contents of a data grid cell needs to be
redisplayed. For example, it occurs when the user selects a cell or scrolls the grid.
With DBGrid1 Set the DataSource Property to DataSource1;
Set the DefaultDrawing Property to False and Edit the OnDrawDataCell Event

OnDrawDataCell Event Code:
procedure TMyStockForm.DBGrid1DrawDataCell(Sender: TObject;
const Rect: TRect; Field: TField; State: TGridDrawState);
begin
{Optional code if you only want to color highlight the CURRENT_VAL column}
{Use this as an example in combination to put color effects
on the grid}
{if Field.FieldName = 'CURRENT_VAL' then begin}
if (Table1PUR_PRICE.Value * Table1SHARES.Value) >= AlertAmount then
DBGrid1.Canvas.Brush.Color:= ColorGrid1.ForeGroundColor
else
DBGrid1.Canvas.Brush.Color:= ColorGrid1.BackGroundColor;
DBGrid1.Canvas.FillRect(Rect);
{ end;}
DBGrid1.Canvas.TextOut(Rect.left + 2, Rect.top + 2,
Field.AsString);
end;

Try this and see what you get.IF it helps you, please, let me know.

Regards,
Eduardo Tavares
www.tavareswebsite.cjb.net
Reply With Quote
  #3  
Old 03-14-2001, 07:22 PM
guqi guqi is offline
Member
 
Join Date: Jan 2001
Posts: 98
Default It changes all col color.

It changes all column color.
I just want to change my specific column color.
Reply With Quote
  #4  
Old 03-14-2001, 07:42 PM
Tavares Tavares is offline
Senior Member
 
Join Date: Feb 2001
Posts: 1,318
Default RE: Try this and tell me.

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
If table1Price.Value > 'Put the value you want then
Dbgrid1.Canvas.Font.Color:= clFuchsia;
Dbgrid1.DefaultDrawDataCell(Rect, dbgrid1.columns[datacol].field, State);
end;

I will be waiting your answer.

Regards,
Eduardo Tavares
www.tavareswebsite.cjb.net
Reply With Quote
  #5  
Old 03-14-2001, 08:01 PM
guqi guqi is offline
Member
 
Join Date: Jan 2001
Posts: 98
Default it works but change all col font but good then before.

It has change all col font color,
Can change specific col font color.
thanks for your kind.
good guy.
Reply With Quote
  #6  
Old 03-14-2001, 08:04 PM
Tavares Tavares is offline
Senior Member
 
Join Date: Feb 2001
Posts: 1,318
Default RE: I will try something here and I send to you tomorrow ok?.

Regards,
Eduardo Tavares
www.tavareswebsite.cjb.net
Reply With Quote
  #7  
Old 03-14-2001, 08:16 PM
guqi guqi is offline
Member
 
Join Date: Jan 2001
Posts: 98
Default good man ok?

Where are you from .
I appreciate you.
Reply With Quote
  #8  
Old 03-14-2001, 08:26 PM
guqi guqi is offline
Member
 
Join Date: Jan 2001
Posts: 98
Default I can not go to your web www.tavareswebsite.cjb.net

my it is the dns problem ,can you give me the Ip,
I am eager to go to your web.
Reply With Quote
  #9  
Old 03-14-2001, 08:29 PM
Tavares Tavares is offline
Senior Member
 
Join Date: Feb 2001
Posts: 1,318
Default RE: I am from Brazil

We are here to help eachother.

Regards,
Eduardo Tavares
www.tavareswebsite.cjb.net
Reply With Quote
  #10  
Old 03-14-2001, 08:31 PM
Tavares Tavares is offline
Senior Member
 
Join Date: Feb 2001
Posts: 1,318
Default RE: I can not go to your web www.tavareswebsite.cjb.net

It might be some problem in cjb.net, keep trying.
Sometimes, I have to try many times to access.
Regards,
Eduardo Tavares
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 07:09 AM.


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