Solved

Problem setting StringGrid Color

Posted on 1997-04-08
7
375 Views
Last Modified: 2012-05-04
I'm having a prboblem setting StringGrid's color to anything but one of the solid system colors, clAqua thru clYellow.  My  video is set for 256 colors and works fine.
There is no problem setting all 256 colors in other components including DrawGrid and DBGrid. What's different about the StringGrid component? Does it use a different pallette or limit the system  pallette?

I'm attempting to use the color dialog to set the color. It should work since its color property is of type TColor which is the same as stringgrid's color property. (When I set my video driver to 16-bit color, stringgrid color work ok).

Thanks,
Jerry G.
0
Comment
Question by:jgrant101
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:javiertb
ID: 1335247
How do you select your DBGrid among 256 colors?
0
 

Author Comment

by:jgrant101
ID: 1335248
Edited text of question
0
 

Author Comment

by:jgrant101
ID: 1335249
javiertb,
You asked how I change the DBGrid's color to one of 256. (Admittedly, I did not check all 256 colors).I use a color dialog control and select a color which I then use to set the DBGrid's color property.  It seems that the stringgrid control either uses a different pallette or limits the system pallette.

Thanks for your help
Jerry G.
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 2

Accepted Solution

by:
javiertb earned 100 total points
ID: 1335250
If you want to get 256 colors to chose from for your component, you'll have to deal with the API functions related to palette creation, manipulation and so on.
0
 

Author Comment

by:jgrant101
ID: 1335251
"If you want to get 256 colors to chose from for your component, you'll have to deal with the API functions related to palette creation, manipulation and so on."

I don't agree with this. Why can I set the color of a DBGrid or a DrawGrid to pastel yellow (color := $A8FFFF) for example, but not the StringGrid?  What's different about the stringgrid? I looked at the VCL souce code but could not find the difference.

Thanks for your help,
Jerry G.
0
 
LVL 2

Expert Comment

by:javiertb
ID: 1335252
Here you have the answer, hope this help:

TCustomGrid defines the FixedColor property and assumes that any code draws the fixed areas will use this propery. TDrawGrid and TStringGrid does this. However, TDBGrid (TCustomDBGrid, actually) defines another property called TitleColor and uses this when drawing. Unfortunately this property is defined as protected making it unavailable for component users at both design and run-time.

The solution is to derive your own component and use this instead of TDBGrid.The following unit does this:


unit Dbgridfx;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, Grids, DBGrids;

type
  TDBGridFix = class(TDBGrid)
  private
    { Private declarations }
    procedure SetFixedFixedColor(Value: TColor);
    function  GetFixedFixedColor: TColor;
  published
    { Published declarations }
    property FixedColor: TColor read GetFixedFixedColor write SetFixedFixedColor default clBtnFace;
  end;

procedure Register;

implementation

procedure TDBGridFix.SetFixedFixedColor(Value: TColor);
begin
  inherited TitleColor := Value;
  inherited FixedColor := Value; { Not really needed, just to be on the safe side }
end;

function TDBGridFix.GetFixedFixedColor: TColor;
begin
  Result := inherited TitleColor;
end;

procedure Register;
begin
  RegisterComponents('Data Access', [TDBGridFix]);
end;

end.

Regards,
Javi
0
 

Author Comment

by:jgrant101
ID: 1335253
You are missing my point. I'm having trouble setting StringGrid's colors. DBGrid and DrawGrid colors can be set as expected.  Your response was to create a new component based on TDBGrid.

Moreover, the problem exists with any row or cell, not just the fixed areas.

Any other suggestions?


0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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