delphi DBgrid coloring

Hi all:

i am writing the following code to on the event DBgirddrawcell,
its working perfect, I'd like to call this event procedure somewhere in the form after update procedure to change the color of rows immediately. i don't know how to pass a parameters to procedure .

procedure TCashier1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
 const
   clPaleGreen = TColor($CCFFCC);
   clPaleRed =   TColor($CCCCFF);
 begin

     If Column.Field.Dataset.FieldbyName('dueamount').ASFLOAT =0 THEN

        If (gdFocused in State)Then
         Begin
         DBGRID1.Canvas.Font.Color:=CLyellow;
         DBGRID1.canvas.brush.color := clBlack;
         End
         Else
         BEGIN
         DBGRID1.canvas.brush.color := clPaleGreen;
         DBGRID1.Canvas.Font.Color:=CLBLUE;
         END;

     If (Column.Field.Dataset.FieldbyName('Status').AsInteger =2) and (Column.Field.Dataset.FieldbyName('paid').ASFLOAT <>0) THEN

        If (gdFocused in State)
         Then DBGRID1.canvas.brush.color := clBlack
         Else
         BEGIN
         DBGRID1.canvas.brush.color := clPaleRed;
         DBGRID1.Canvas.Font.Color:=CLBLUE;
         END;
     DBGRID1.DefaultDrawColumnCell(rect,DataCol,Column,State)
end;

Open in new window

khaled salemSoftware DeveloperAsked:
Who is Participating?
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
just call dbgrid1.refresh, for example in datasour.onstatechange

procedure TForm1.DataSource1StateChange(Sender: TObject);
begin
  DBGrid1.Refresh;
end;
0
 
khaled salemSoftware DeveloperAuthor Commented:
i am trying , but the color doesn't appear .
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
which color? As the grid could be not focused, refreshing it from external procedure you should see it in palegreen or palered
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Sinisa VukCommented:
Do not call DefaultDrawColumnCell at all, and set DefaultDrawing := False.
0
 
khaled salemSoftware DeveloperAuthor Commented:
Hi all :

More explain,  the DBgrid1 is connected to MyQuery1. when i make double click on one row its open new form (receipt from) to receive the money, in this new form i make update to the row that selected by the main form i would like to change the color of selected row in the main form according to the update. without call the select query again to keep the cursor on this row.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
but you have definitely to requery your new data, as you're updating them by an external object
0
 
Sinisa VukCommented:
Set query to be writable, make edit on current record, change values and post.
For Ado...

...before open query...
    
...
    MyQuery1.CursorLocation:=clUseClient;
    MyQuery1.CursorType:=ctStatic;
    MyQuery1.LockType:=ltPessimistic;
    MyQuery1.Open;
...

Open in new window

..on other form close...
...
  MyQuery1.FieldByName('Field1').ReadOnly := False;
  MyQuery1.Edit;
  MyQuery1.FieldByName('Field1').AsString := '123';
  MyQuery1.Post;
...

Open in new window


(...but this is different question :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.