Solved

DBGrid Selected Row Color

Posted on 2000-04-13
9
576 Views
Last Modified: 2010-04-04
Very Simple Q

Delphi5 Hase A DBGrid .Ok.
How can I Change The Color Of Selected Row From Blue To Any Other Color

I Can't Use Any Other Components Due to
BiDiMode Selection I Must Use The DBGrid That Came With Delphi5.
0
Comment
Question by:zaferms
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 4

Expert Comment

by:jeurk
ID: 2712952
in your ondrawcolumncell add :
  //highlight the focused lines
  if ((gdFocused in State) then
  begin
    theGrid.Canvas.Brush.Color := clYourColor;
    theGrid.Canvas.FillRect(Rect);
  end
  else
  begin
    theGrid.Canvas.Brush.Color := clBtnFace;
    theGrid.Canvas.FillRect(Rect);
  end;

  // make the output rectangle a bit smaller to have a small distance from the borders
  InflateRect(Rect, -2, -2);

  //draw the text right or left aligned
  if (Col > 0) and not (gdFixed in state) then
    DrawText(theGrid.Canvas.Handle, PChar(S), Length(S), Rect, DT_RIGHT)
  else
    DrawText(theGrid.Canvas.Handle, PChar(S), Length(S), Rect, DT_LEFT);

or to let delphi draw the text for you call DefaultDrawColumnCell after the fillrect

cU
0
 
LVL 3

Accepted Solution

by:
Stefaan earned 30 total points
ID: 2715385
Hi Jeurk & Zaferms,

There is an easier way to do it.

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if (gdSelected) in State then
  begin
    DBGrid1.Canvas.Brush.Color := clMaroon;
    DBGrid1.DefaultDrawColumnCell (Rect, DataCol, Column, State);
  end;
end;

There is no need to use the DrawText, you can let Delphi do the drawing by using the DefaultDrawColumnCell.
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2715396
euh, and what is different with what I say ?
That's what I say at the end, that we can use DefaultDrawColumnCell to draw the text. I left the drawtext, to show how to do it.
But I agree, what you say is somewhat cleaner...

CU
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2715480
Here is another example:

http://community.borland.com/article/0,1410,20845,00.html

Cheers,

Raymond.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:Stefaan
ID: 2715571
Jeurk,

If you do it like I showed, there is no need to call the DBGrid1.Canvas.FillRect(Rect) Method.

So you save some lines of code ;-)
0
 

Author Comment

by:zaferms
ID: 2715713
Thanx Jeurk & stefaan

you are Great both of you

iam confused  how can i grade you both

jeurk : your code is good but long thou
but still work.

stefaan : your code is short and good

please tell me how can i grade you both

or one of you

thanks all


0
 
LVL 3

Expert Comment

by:Stefaan
ID: 2715726
Well, you could always split the points ;-)
0
 

Author Comment

by:zaferms
ID: 2715874
how stefaan
0
 
LVL 3

Expert Comment

by:Stefaan
ID: 2715944
Well, reward one of the us with the points and post a new question with title :

Points for <name>

And add a comment here so that the second user gets notified that he can get his points on another question
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
creating threads in delphi 1 84
Find and Replace Stream with 0s 8 57
how can i search if string exist in array ? 3 50
Dev express lookupcombo 3 14
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now