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

x
?
Solved

Default color change for the selected row

Posted on 2000-05-01
5
Medium Priority
?
351 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 60 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

Industry Leaders: 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!

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…
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…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

927 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