Subject Re: [IBO] Awkward to use drawcell
Author Luiz
Thomas
You may use:
1. A calculated field, maybe called 'CALC_STATUSINDEX' and fill your values
on event onCalculateField.
2. On event OnGetCellProps of the Tib_Grid do something as:

procedure TYourForm.IB_Grid1GetCellProps(Sender: TObject; ACol,
ARow: Integer; AState: TGridDrawState; var AColor: TColor;
const AFont: TFont);
var Fcor:Tcolor;
tmpFld: TIB_Column;
stix:Integer;
begin
with Sender as TIB_Grid do begin
if not Datasource.Active then exit;
if (ACol>FixedDataCols) and (ARow<>0) then begin
with Datasource.Dataset do begin
BufferRowNum := DataRow[ ARow ];
if BufferRowNum > 0 then begin
tmpFld := BuffFields[ DataCol[ ACol ]];
if Assigned( tmpFld ) then begin
if ( tmpFld.FieldName = 'CALC_STATUSINDEX' ) then begin
stix:=BufferFieldByName('STATUSINDEX').AsInteger;
case stix of
six_unserviced : Fcor:=clred;
six_needservice : Fcor:=clgray;
six_serviced : Fcor:=clgreen;
else Fcor:=clgray;
end;
AColor:=Fcor;
end;
end;
end;
end;
end;
end;
end;

procedure TYourForm.your_qyeryCalculateField(Sender: TIB_Statement;
ARow: TIB_Row; AField: TIB_Column);
var stix:Integer;
s:String;
begin
with AField do begin
if FieldName='CALC_STATUSINDEX' then begin
stix:=ARow.ByName('STATUSINDEX').AsInteger;
case stix of
six_unserviced : s:='Us';
six_needservice : s:='Ns'
six_serviced : s:='S';
else s:='?';
end;
ARow.ByName('CALC_STATUSINDEX').asString:=s;
end;
end;

I didn't test, maybe your have to do some small fixes.

Luiz.

----- Original Message -----
From: "thomasjensenus" <tje@...>
To: <IBObjects@yahoogroups.com>
Sent: Friday, May 03, 2002 6:22 AM
Subject: [IBO] Awkward to use drawcell


> Hi,
>
> I need to paint user-drawn cells in a grid control.
> An integer need to be painted as a special colored item.
>
> The stupid thing is that I can't seem to get the integer
> value in the drawcell method, thus I get the integer as
> a string and then translate that back to an integer...
>
> Using AColum.AsInteger returns random values.
>
> The code below describes the problem.
> Any suggestions?
>
> Thomas
>
>
>
> procedure Tmainform.devicesgridDrawCell(Sender: TObject; ACol,ARow:
> Integer; Rect: TRect; State: TGridDrawState);
> var ix,stix : integer;
> s : string;
> c : tcolor;
> AColumn : TIB_Column;
> begin
> if (dbdata=nil) or not dbdata.devicesds.prepared then
> exit;
> with dbdata,devicesgrid do
> begin
> s:=GetCellDisplayText(acol,arow);
> if s<>'' then
> begin
> ix:=DataCol[aCol];
> AColumn:=GridFields[ix];
> if (AColumn<>nil) and (ARow>=FixedRows) and (ix>=0) and
> (ansiuppercase(AColumn.FieldName)='STATUSINDEX') then
> begin
> stix:=strtoint(s);
> with devicesgrid.canvas do
> begin
> case stix of
> six_unserviced : begin
> s:='Us';
> c:=clred;
> end;
> six_needservice : begin
> s:='Ns';
> c:=clgray;
> end;
> six_serviced : begin
> s:='S';
> c:=clgreen;
> end;
> else begin
> s:='?';
> c:=clgray;
> end;
> end;
> brush.color:=c;
> fillrect(rect);
> textout(rect.left+2,rect.top+1,s);
> if gdfocused in state then
> drawfocusrect(rect);
> end;
> end;
> end;
> end;
> end;
>
>
>
>
>
>
___________________________________________________________________________
> IB Objects - direct, complete, custom connectivity to Firebird or
InterBase
> without the need for BDE, ODBC or any other layer.
>
___________________________________________________________________________
> http://www.ibobjects.com - your IBO community resource for Tech Info
papers,
> keyword-searchable FAQ, community code contributions and more !
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>