We help IT Professionals succeed at work.
Get Started

DBGRID on cell draw

Scay7
Scay7 asked
on
3,840 Views
Last Modified: 2012-05-11
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

Comment
Watch Question
Freelance Project Manager
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE