Subject Re: [IBO] Display Icon in a Grid
Author Markus Ostenried
At 20:30 Saturday, 31.01.2004 +0100, you wrote:
>Markus,
>
>thanks for that code.
>
>It works insofar that there are icons shown in the grid, but the grid
>behaves strange.
>Say I have three rows with different icons, after filling the grid, all
>rows show the same icon.
>When I click into a row, the assigned icon for that row is shown, the
>other two rows show either one
>of the other two, couldn't figure out any pattern.

be sure to operate on the query's buffer. If you locate the row to be drawn
within the buffer with "BufferRowNum := .." then you have to access its
values with BufferFieldByName (see other BufferXXXX methods, too). The
normal call to FieldByName will only give you the values of the record
currently selected in the grid - not the other records that need to be
drawn, too.

You can paste your code here, so that we can have a look at it.

I just did a search through my IBO mail archive and found some examples for
OnDrawCEll and OnGetCellProps (which is similiar to use):

// From: "Thomas Steinmaurer" <ts@...>
// Subject: RE: [IBO] Question about TIB_Grid.OnDrawCell
// I'm using the OnGetCellProps event. Dependent of a column value
// the font and background color is set.
// The Contact sample in %IBO%\Samples\Contact might be useful too.
// An example (not fully checked, but you might get the idea):

procedure TfmMainForm.IB_Grid1GetCellProps(Sender: TObject; ACol, ARow:
Integer;
AState: TGridDrawState; var AColor: TColor; AFont:
TFont);
begin
with IB_Query1 do
begin
if Active and (ARow > 0) and (ACol > 0) then
begin
BufferRowNum := IB_Grid1.DataRow[ARow];
if (BufferRowNum > 0) then
begin
if not (gdSelected in AState) then
begin
AFont.Color := BufferFieldByName('FONTCOLOR').AsInteger;
AColor := BufferFieldByName('BACKGROUNDCOLOR').AsInteger;
end;
end;
end;
end;
end;

// From: "John Peterson" <jcp@...>
// Subject: Re: [IBO] Re: bmp in tib_grid
procedure TilvsClientForm.JobGridDrawCell(Sender: TObject; ACol, ARow:
Integer;
Rect: TRect; State: TGridDrawState);
begin
if jobGrid.DataSource.DataSet.Active then
if ACol = BOOLEANCOLUMN then begin
if JobGrid.BuffFields[Acol-1].AsBoolean = TRUE then
JobGrid.Canvas.Draw(Rect.Left,Rect.Top,BitMapTick)
else
JobGrid.Canvas.Draw(Rect.Left,Rect.Top,BitMapCross);
end else
with jobGrid do DefaultDrawCell( ACol, ARow,
Rect,
State,
GetCellDisplayText( ACol, ARow ),
GetCellAlignment( ACol, ARow ));
end;

// From: "Luiz" <cprmlao@...>
// Subject: Re: [IBO] Awkward to use drawcell
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;


To Helen: I have searched the IBO online faq for TIB_Grid and controls but
haven't found an example like the above. Maybe you can add one ?

bye,
Markus