Subject | Awkward to use drawcell |
---|---|
Author | thomasjensenus |
Post date | 2002-05-03T09:22:30Z |
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;
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;