Link to home
Start Free TrialLog in
Avatar of jgrant101
jgrant101

asked on

Problem setting StringGrid Color

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.
Avatar of javiertb
javiertb

How do you select your DBGrid among 256 colors?
Avatar of jgrant101

ASKER

Edited text of question
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.
ASKER CERTIFIED SOLUTION
Avatar of javiertb
javiertb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"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.
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
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?