Solved

DBgrid coloring on var calculated onformshow

Posted on 1998-10-22
3
451 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
Comment Utility
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
Comment Utility
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
Comment Utility
Wow,

Sorry I forgot to close out the question.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now