Solved

Default color change for the selected row

Posted on 2000-05-01
5
342 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
Comment Utility
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
Comment Utility
Too late !

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

Expert Comment

by:SuperSy
Comment Utility
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
Comment Utility
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
Comment Utility
Answer accepted
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

12 Experts available now in Live!

Get 1:1 Help Now