troubleshooting Question

DBGRID on cell draw

Avatar of Scay7
Scay7Flag for South Africa asked on
Delphi
5 Comments1 Solution3841 ViewsLast Modified:
Ello all, cant for the life of me figure out why it wont stick...
I have a dbgrid.ondrawcell procedure that draws the colours fine but it wont keep the bitmaps in the cell only when you click or highlight the cell does the bitmap appear but if you move the the next record the bitmap disappears....

Here is the procedure...

Procedure dw(rect: trect; imgl : integer);
var
bitmap : TBitmap;
begin
  bitmap := TBitmap.Create;
  try
    form1.ImgList.GetBitmap(imgl,bitmap);
    form1.dbgrid.Canvas.FillRect(rect);
    form1.DBGrid.Canvas.Draw(Rect.left,rect.Top+1,bitmap);
  finally
  bitmap.Free;
  end;
end;

procedure TForm1.DBGridDrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin

if Column.Field.Dataset.FieldbyName('dnfee').AsString = '1' then
  if column.FieldName = 'ico' then dw(rect,1);
if Column.Field.Dataset.FieldbyName('oasts').AsString = '' then
  if column.FieldName = 'ico' then dw(rect,0);

If Column.Field.Dataset.FieldbyName('dbcs').AsString = '4' then 
dbgrid.canvas.brush.color := clyellow;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '6' then 
dbgrid.canvas.brush.color := clmoneygreen;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '7' then 
dbgrid.canvas.brush.color := clskyblue;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '12' then 
dbgrid.canvas.brush.color := cllime;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '14' then 
dbgrid.canvas.brush.color := clfuchsia;

If Column.Field.Dataset.FieldbyName('dbcs').AsString = '1' then
begin
dbgrid.canvas.Font.Color := clcream;
dbgrid.canvas.brush.color := clred;
end;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '2' then
begin
dbgrid.canvas.Font.Color := clcream;
dbgrid.canvas.brush.color := clgreen;
end;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '3' then
begin
dbgrid.canvas.Font.Color := clcream;
dbgrid.canvas.brush.color := clblue;
end;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '5' then
begin
dbgrid.canvas.Font.Color := clcream;
dbgrid.canvas.brush.color := clmaroon;
end;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '8' then
begin
dbgrid.canvas.Font.Color := clcream;
dbgrid.canvas.brush.color := clolive;
end;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '9' then
begin
dbgrid.canvas.Font.Color := clcream;
dbgrid.canvas.brush.color := clnavy;
end;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '10' then
begin
dbgrid.canvas.Font.Color := clcream;
dbgrid.canvas.brush.color := clpurple;
end;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '11' then
begin
dbgrid.canvas.Font.Color := clcream;
dbgrid.canvas.brush.color := clgray;
end;
If Column.Field.Dataset.FieldbyName('dbcs').AsString = '13' then
begin
dbgrid.canvas.Font.Color := clcream;
dbgrid.canvas.brush.color := clteal;
end;

dbgrid.DefaultDrawColumnCell(rect,DataCol,Column,State);
end;

Open in new window

ASKER CERTIFIED SOLUTION
Emmanuel PASQUIER
Freelance Project Manager

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2010

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros