Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DBGrid Selected Row Color

Posted on 2000-04-13
9
Medium Priority
?
604 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 120 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

972 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