If I understood what do you want I prefer another approach.
In the button1 click event I would fetch the data and I would fill not the 
cells but the objects of the cells
with the a flag about the color I want, like 

   SG.Objects[col,row]:= TObject(n) 
where n could be an integer that denotes the index in a collor array e.g. 
MyArrayOfColors[1..3] of TColor

Then in the
procedure TOverviewForm.SGDrawCell(Sender: TObject; ACol, ARow:Integer;Rect: 
TRect; State: TGridDrawState);

i would have
      idx := Integer(SG.Objects[Acol, Arow);
     if idx>0 then
     begin
      SG.Canvas.Brush.Color := MyArrayOfColors[Integer(SG.Objects[Acol, Arow)]
      SG.Canvas.FillRect(Rect);
    end;
==========
So there is not need to fetch all the time the data
The code is by mind so just catch the idea
Sorry for my english
Antonis Tsourinakis

*********** REPLY SEPARATOR  ***********

On 26/07/2006 at 12:12 Wilson, Stephen wrote:

>Hello all
>
>I want to query a dataset and then represent the nature or state of that
>data by one of three different colours (essentially red if a field
>contains data in all rows, amber if a field contains data in some rows but
>not others, and green if a field contains data in none of the rows).
>
>The following code shows what I did in a rough and ready solution using
>the OnDrawCell of a TStringGrid, which is not a workable solution since
>the process starts from scratch each time the Grid is repainted (so, for
>example, if you return to the Grid's form after focusing on another
>application).
> There will be, of course, many ways of achieving the objective, but what
>might be the most efficient (using any components - Grid does not have to
>feature) ?
>
>Thanks for any suggestions
>
>Regards
>Steve
>
>---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>procedure TOverviewForm.SGDrawCell(Sender: TObject; ACol, ARow:
>Integer;Rect: TRect; State: TGridDrawState);
>var i, j, count: Byte;  colour: TColor;  theDate: TDateTime;
>begin
>for j:= 1 to max do
> begin
>  theDate:= StrToDateTime(inttostr(j) + '/' + inttostr(mnth) + '/' + yr);
>  getData(theDate); // Gets data for a single day
>  for i:= 2 to Q_Overview.FieldCount-1 do
>   begin
>    Q_Overview.First;
>    count:=0;
>    while not Q_Overview.Eof do    // Iterates over each column in turn
>and counts the cells containing data
>      begin
>       if  Q_Overview.Fields[i].AsString > '' then
>         inc(count);
>       Q_Overview.Next;
>      end;
>    if count > 0 then                   // Sets variable colour according
>to value of variable count
>     begin
>       if count = 27 then
>        colour:= $001111FF
>       else
>        colour:= $001BBFF
>     end
>    else
>      colour:= $0044DE44;
>    if (ACol = i-1) and (ARow = j)  then
>     begin
>      SG.Canvas.Brush.Color := colour;
>      SG.Canvas.FillRect(Rect);
>     end;
>   end;
> end;
>end;
>
>
>
>procedure TOverviewForm.Button1Click(Sender: TObject);
>var i: Byte;
>begin
>//starttime:= gettickcount;
>mnth:= cb_Month.ItemIndex+1;
>yr:= cb_Year.Text;
> case mnth of
>  1,3,5,7,8,10,12: max:= 31;
>  4,6,9,11: max:= 30;
>  2: if isLeapYear(strtoint(yr)) then max:= 29 else max:= 28;
> end;
>
>for i:= 1 to max do
> SG.Cells[0,i]:= FormatDateTime('ddd  d',StrToDateTime(inttostr(i) + '/' +
>inttostr(mnth) + '/' + yr));
>SG.Repaint;         // have grid repaint itself
>{endtime:= gettickcount;
>secondstaken:= (endtime-starttime)/1000;
>showmessage('Time taken = ' + floattostr(secondstaken) + ' secs'); }   //
>Takes about 45 secs from start to finish with 14 data fields and 28 - 31
>rows 
>end;
>
>***************************************************************************
>This e-mail and any files transmitted with it are confidential. If you are
>not the intended recipient, any reading, printing, storage, disclosure,
>copying or any other action taken in respect of this e-mail is prohibited
>and may be unlawful. If you are not the intended recipient, please notify
>the sender immediately by using the reply function and then permanently
>delete what you have received.
>Content of emails received by this Trust will be subject to disclosure
>under the Freedom of Information Act 2000, subject to the specified
>exemptions, including the Data Protection Act 1998 and Caldicott Guardian
>principles.
>This footnote also confirms that this email message has been swept by
>MIMESweeper and Sophos Anti-virus for the presence of computer viruses.
>***************************************************************************
>
>
>
>
>-----------------------------------------------------
>Home page: http://groups.yahoo.com/group/delphi-en/
>To unsubscribe: [EMAIL PROTECTED] 
>Yahoo! Groups Links
>
>
>





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Something is new at Yahoo! Groups.  Check out the enhanced email design.
http://us.click.yahoo.com/TktRrD/gOaOAA/yQLSAA/i7folB/TM
--------------------------------------------------------------------~-> 

-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to