?
Solved

delphi DBgrid coloring

Posted on 2012-09-17
7
Medium Priority
?
801 Views
Last Modified: 2012-10-07
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

0
Comment
Question by:khaled salem
  • 3
  • 2
  • 2
7 Comments
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 1000 total points
ID: 38407492
just call dbgrid1.refresh, for example in datasour.onstatechange

procedure TForm1.DataSource1StateChange(Sender: TObject);
begin
  DBGrid1.Refresh;
end;
0
 

Author Comment

by:khaled salem
ID: 38408577
i am trying , but the color doesn't appear .
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 38408592
which color? As the grid could be not focused, refreshing it from external procedure you should see it in palegreen or palered
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:Sinisa Vuk
ID: 38408959
Do not call DefaultDrawColumnCell at all, and set DefaultDrawing := False.
0
 

Author Comment

by:khaled salem
ID: 38409296
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
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 38409340
but you have definitely to requery your new data, as you're updating them by an external object
0
 
LVL 28

Expert Comment

by:Sinisa Vuk
ID: 38409397
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question