Subject Re: [IBO] ib_grid.ondrawcell and ongetcellprops
Author Markus Ostenried
Hi,

At 08:59 Thursday, 10.07.2003 +0000, you wrote:
>well I dont understand what the first part is ... the bufferrownum?

A TIB_Query (and everything derived from TIB_BDataSet) is a buffered
dataset. That means it can fetch many records from the server and then keep
them in a memory buffer. A TIB_Cursor always has only one record, then
"forgets" the current record and fetches the next record from the server
and so on. But with the TIB_Query you can get some records from the server
and then scroll in the dataset, that is call First, Next, Last etc to
navigate through the fetched records on the client.

In a buffered dataset you have two sets of methods: The "normal" methods
like First, Next, FieldByName etc. Using these will affect the visual
interface (the attached controls on your form) by changing the current
record in the grid for example. The other set is the "buffer" methods like
BufferFirst, BufferEoF, BufferFieldByName etc. They only operate on the
record buffer of the dataset without changing the controls. These two sets
can be used independently from each other, which means you can call First
and the grid will mark the first record as the current one and then you can
call BufferLast and read the data of the last record in your dataset
without the grid changing.

In the OnGetCellProps event you need to know the content of some columns to
determine which color you want to use. You cannot use the "normal" methods
here because this would change the grid's current record. But you can use
the "buffer" equivalents of the methods.

RowNum is simply the number/index of a record in a dataset. Be aware that
the RowNum can change when you do a re-fetch of the records. If you need
persistent record identification use Bookmarks or your primary key. By
setting RowNum you make another record the current one like e.g. calling
Locate(...). Setting BufferRowNum does this in the buffer only without
changing the controls.

dsContact.DataSet.BufferRowNum := grContact.DataRow[ ARow ];

ARow is the parameter you get in the OnGetCellProps event. It tells you
which grid row the cell belongs to that is to be drawn. With
Grid.DataRow[ARow] you get the corresponding RowNum of the dataset that
holds the record that is painted in the grid's row ARow. In the buffer of
the dataset this record is located by setting BufferRowNum. You can now
access the fields of this record with for example
BufferFieldByName('MyField').AsString.

> the purpose of the tmpfld?

tmpFld := grContact.GridFields[ grContact.DataCol[ ACol ]];

Then you need to know which database column the grid cell is displaying.
Because the order of a grid's columns can be changed by dragging the column
headers you need to translate the grids column index ACol to the column
index in dataset. This is done with Grid.DataCol[ACol]. The GridFields[]
property then gives you a TIB_Column object - like tmpFld :=
Dataset.FieldByName('bla'); does.

> assigned(tmpfld)?
This check is needed because the OnGetCellProps event can be called at a
time when the dataset isn't yet prepared. Then you woudn't get a TIB_Column
object from the grid but nil instead.

>As I have said I did get my grid working but why is it that my column
>title has turn red also?

type
TGridDrawState = set of (gdSelected, gdFocused, gdFixed);

To avoid changing the grid's column header write something like
if not (gdFixed in AState) then SetYourColors;

>And I have notice that if the i have select
>a record which satisfy to the condition that makes its font turn to
>red and when I go backward thru the record the first column of that
>record turns red also? and when I scroll it again it turns back to
>black.

I cannot quite imagine what's happening here. Maybe you can show us your
code for the event ?

Well, this has become a quite long post. I hope that everything I wrote is
right - I'm not an IBO guru either. But if not I'm sure the others will
correct me.

HTH,
Markus