Solved

DBgrid coloring on var calculated onformshow

Posted on 1998-10-22
3
455 Views
Last Modified: 2010-04-03
I want to color the cells of my dbgrid depending upon a variable which is calculated in a procedure invoked 'on formshow.' Currently, the 'ondrawcolumncell' event appears to happen before 'onformshow.' I'm looking for a suggestion how to paint the cells based on this calculated variable.

The data doesn't exist when the form is initially created.

I am looking for a suggestion to get the grid colored properly.
0
Comment
Question by:oneeye
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1343876
oneeye,

hup, q'n already entered... heck, here was my answer :

the ondrawcolumncell normally appears after the onshow event...

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  holdColor: TColor;
begin
  holdColor := DBGrid1.Canvas.Brush.Color; {store the original color}
  if Column.FieldName = 'Species No' then
    if (Column.Field.AsInteger > 90070) then begin
      DBGrid1.Canvas.Brush.Color := clGreen;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      DBGrid1.Canvas.Brush.Color := holdColor;
    end;
end;

Regards, Zif.


0
 

Author Comment

by:oneeye
ID: 1343877
Ah, thank you. Both your answers were very helpful. I do have one additional question, if you could be so kind. Am I correct in assuming that the column drawing method does not page through the records in the table on the draw? What I ended up doing was using as the first column in the dbgrid the variable I calculated as a column 1 pixel wide to set the color of the rest of the columns on that row. This works fine, I was pondering about other more elegant ways of doing this, though.
0
 

Author Comment

by:oneeye
ID: 6968640
Wow,

Sorry I forgot to close out the question.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 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