Enabling/disabling grid columns [query]

I am looking for a way of enabling or disabling a column in a dbgrid at
runtime, dependent on the value in another column, similar to the way
individual text fields can be enabled. Any suggestions would be

Kym Wilson

Details of the problem follow:

I have an application which includes a table of depths, which has the following

CODE   C 6             identifying code
DEPTH  N 7 2           actual depth value
REL    L               flag to indicate absolute or relative depth
REF    C 6             depth code for relative reference
OFFSET N 7 2           depth offset from reference depth

If REL is false then the user can directly edit DEPTH. If REL is true then
the user can enter REF which must be the code for an existing depth record.
THe program then looks up the value of DEPTH in the reference record (in a
second table) and then adds OFFSET and writes this value to DEPTH.

I have two forms which display the depth table, both created with the database
expert. The first form displays the depth table as a grid and the second as an
edit form. These are linked so that the highlighted record on the grid is
displayed on the edit form. This amounted to about 10 lines of code changes
as per example on pages 95-96 of the Database Application Developers guide.
(It took me days to write an equivelant in VB!)

I have managed to modify the form so that when REL is true, the Tdbedit for
DEPTH has enabled false etc. as per the following:

       if checkboxrel.state=cbchecked then

When either REF or OFFSET change I calculate the new value of depth and write
it in using :


(table2 is the second copy of depth used to lookup REF)

The good news is that this all works (and well!) The user cannot select DEPTH
directly when REL is checked but it is automatically updated whenever the
reference or offset change.

I then tried to apply the same features to the Tdbgrid  and there I have

If I set the READONLY flag on the DEPTH column when REL is true then the field
can still be selected and edited but the value is reset to the original when
the cell is exited. This achieves the end result but is not very elegant for
the user.

Also it prevents me from updating the value in the edit form unless I
change the readonly property back to false, save the record and then set it
back to true. I haven't quite worked out which events to put the statements
in so these things happen in the correct sequence.

I also tried to modify the Ongettext event so that the cursor would move to
the REL column when the DEPTH column was selected if REL was true (and
similarly for REF and OFFSET when REL was false. However this resulted in
DEPTHS not being displayed.

What I am looking for is a way to emulate  the ENABLED property for a column
in a grid, so that the program can read and write to it but the user can't
select it.