Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DBGrid Selected Row Color

Posted on 2000-04-13
9
Medium Priority
?
599 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

670 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