Martin Barreda
asked on
Colors in DBGrid
Welcome you all!
What i need is this:
* Color the rows of a DBGrid which datasource is a Paradox table depending on the value of one of the fields of each record. eg: if field A gets the values 0, 1, 2 and 1 in four record then the first row must be red, the second blue, the third green and the last one blue again.
I am working with Delphi 6 Enterprise.
Thanks...
What i need is this:
* Color the rows of a DBGrid which datasource is a Paradox table depending on the value of one of the fields of each record. eg: if field A gets the values 0, 1, 2 and 1 in four record then the first row must be red, the second blue, the third green and the last one blue again.
I am working with Delphi 6 Enterprise.
Thanks...
exactly
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
...
ASKER
Sorry about the delay but i check this only twice a day.
I try Nestorua solution (which is more accurate) and works fine for what i want.
The two solution get me into the idea.
One more, I now trying to get a graphic in the same grid in one column, one for each value of the same field.
I put it into the data of the table but I only get a (GRAPHIC) description. The graphic is a simple bitmap and i think i can wrote into the same code something like this
var bmp: TBitmap;
...
if (DataSource.DataSet[YourFi eldName]=0 )
then
begin
if gdSelected in State
then
begin
Brush.Color:=clRed;
Font.Color :=clAqua;
bmp := TBitmap.Create;
imagelist1.GetBitmap(DataS ource.Data Set[YourFi eldName].A sInteger, bmp);
Canvas.Draw(Rect.Top + 2, Rect.Left + 2,bmp);
bmp.Free;
DefaultDrawColumnCell(Rect , Field, State);
end
...
But the bitmap is drawn at the top of the grid or behind it.
Thanks you
I try Nestorua solution (which is more accurate) and works fine for what i want.
The two solution get me into the idea.
One more, I now trying to get a graphic in the same grid in one column, one for each value of the same field.
I put it into the data of the table but I only get a (GRAPHIC) description. The graphic is a simple bitmap and i think i can wrote into the same code something like this
var bmp: TBitmap;
...
if (DataSource.DataSet[YourFi
then
begin
if gdSelected in State
then
begin
Brush.Color:=clRed;
Font.Color :=clAqua;
bmp := TBitmap.Create;
imagelist1.GetBitmap(DataS
Canvas.Draw(Rect.Top + 2, Rect.Left + 2,bmp);
bmp.Free;
DefaultDrawColumnCell(Rect
end
...
But the bitmap is drawn at the top of the grid or behind it.
Thanks you
HI,
It's much more reasonable to use TDBImage or TDBCtrlGrid components for your purpose.
Sincerely,
Nestorua.
It's much more reasonable to use TDBImage or TDBCtrlGrid components for your purpose.
Sincerely,
Nestorua.
ASKER
May be, but is faster with the DBGrid, because is just three types of square what i need to show. Besides, i do not get into the data that graphic.
If what i want has an easy solution i would like that, but the DBCtrlGrid may be the best solution.
Thanks, i wait for some answer to this and give you the answer...
Thanks you all!!
If what i want has an easy solution i would like that, but the DBCtrlGrid may be the best solution.
Thanks, i wait for some answer to this and give you the answer...
Thanks you all!!
procedure TForm1.DBGrid1DrawColumnCe
var
AColor: TColor;
begin
case Table1.Fields[2].AsInteger
0: AColor := clRed;
1: AColor := clBlue;
2: AColor := clGreen;
end;
with Sender as TDBGrid do
begin
Canvas.Brush.Color := AColor;
Canvas.FillRect(Rect);
DefaultDrawColumnCell(Rect
end;
end;
HTH
DragonSlayer