Solved

Default color change for the selected row

Posted on 2000-05-01
5
343 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
  • 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

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
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…

895 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

13 Experts available now in Live!

Get 1:1 Help Now