Solved

Default color change for the selected row

Posted on 2000-05-01
5
349 Views
Last Modified: 2010-04-04
How can I change the default color for the selected row (default is blue) in a TDbGrid control ?
0
Comment
Question by:drnadeem
[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
  • 2
  • 2
5 Comments
 

Accepted Solution

by:
SuperSy earned 20 total points
ID: 2766857
Here's what you gotta do.

(1) Set the DBGrid's DeafultDrawing property to False.

(2) Make an OnDrawColumnCell event handler, and make it like this.

procedure TyForm.MyDBGridDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  // Turn TDBGrid.DefaultDrawing off (False) before doing all this
  if (gdSelected in State) then
    with Canvas do
    begin
      Brush.Color := clBlack; // Background color to Fill a Rectangle
      FillRect(Rect);         // Fill the whole cell
    end;
  // Draw things originally intended by Delphi
  MyDBGrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

This should do for a selected cell or row when dgRowSelect is True.

And by the way, you might want to get rid of the other three duplicate questions before someone else answers them...
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2768714
Too late !

I got in first, but I'll share the points with you, SuperSy ! :-)
0
 

Expert Comment

by:SuperSy
ID: 2770415
It would be nice if we can both get 20 points each...but I think ultimately it's up to drnadeem to decide upon whom he awards the points.  

I got my answer in before yours (11:41AM vs 10:30PM)...but your code is smaller and neater. If drnadeem thinks you win, so be it.  =)

Last thing I want is getting into one of those "I don't want points but I deserve some and it's your fault to begin with because blah blah blah" kind of war.  

I hope drnadeem got what s/he wanted.

SuperSy
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2771430
I actually think your answer is better. It's the same as mine, however you gave a code example, whereas I did not. I also thought it humourous to 'fight' over 20 points.
:-))))
0
 
LVL 1

Author Comment

by:drnadeem
ID: 2944357
Answer accepted
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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

636 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