Board index » delphi » TDBGrid : Repositioning columns at runtime (HELP)

TDBGrid : Repositioning columns at runtime (HELP)

Anyone know how to do this ?

Basically I have a TDBGrid component, if the user drags / sizes the
fields in the grid, this is recorded and written to an INI file.  I
know which fields have been dragged to where in the order of the grid
by the .FieldNo property, but this is read only and I can't work out
how to restore this layout when the application loads...

---- Phil

 

Re:TDBGrid : Repositioning columns at runtime (HELP)


Quote
p...@mayo.demon.co.uk (Phil Askey) wrote:
>Anyone know how to do this ?

>Basically I have a TDBGrid component, if the user drags / sizes the
>fields in the grid, this is recorded and written to an INI file.  I
>know which fields have been dragged to where in the order of the grid
>by the .FieldNo property, but this is read only and I can't work out
>how to restore this layout when the application loads...

>---- Phil

Good question, let me know if you get an answer.  I think that what you want
is persistant column repositioning.

Re:TDBGrid : Repositioning columns at runtime (HELP)


Quote
In article <817040580.19...@mayo.demon.co.uk> p...@mayo.demon.co.uk (Phil Askey) writes:
>Basically I have a TDBGrid component, if the user drags / sizes the
>fields in the grid, this is recorded and written to an INI file.  I
>know which fields have been dragged to where in the order of the grid
>by the .FieldNo property, but this is read only and I can't work out
>how to restore this layout when the application loads...

I am doing something similar but not identical, so I have not tested the
advice.

To change the position, set Grid.Fields[I].Index to what you want it to be.  
But you have to be careful from then on, because the order changes
(immediately, I think), and the other field indexes are changed, accordingly.  
I search on field name, then set the index, IN INCREASING FIELD ORDER from 0.  
Then I set the unused fields to not visible (these have conveniently been
pushed to the end of the order).

The fact that the indexes are dynamic (and change with visibility too) makes
fiddling quite tricky.  It is easy to doubt your sanity.

Andrew
==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==
Andrew Gabb                     a...@itd.dsto.gov.au
Information Technology Division
Defence Science and Technology Organisation
Ph  +61 8 259 5505    Fax +61 8 259 5980
171 Labs ITD/DSTO, P.O. Box 1500, Salisbury S.A., Australia 5108

Re:TDBGrid : Repositioning columns at runtime (HELP)


The property DisplayWidth of the fields (in characters!) can
be set at run time and should, I hope, resolve your problem...
                                                   Vincent

Re:TDBGrid : Repositioning columns at runtime (HELP)


Quote
Vincent Schmid <vschm...@worldcom.ch> wrote:
>The property DisplayWidth of the fields (in characters!) can
>be set at run time and should, I hope, resolve your problem...
>                                                   Vincent

I lost the beginning of this thread but I wrote a unit (FLDINFO) that
saves the width and position of a DBGrid.  (Actually, this is kept in
the TTable component!)  You can find it at
http:/www.etcconnect.com/fitco.html or on the "Super Delphi Page".

-------------------------------------
Bill Florac: fl...@etcconnect.com
Fitco: http://www.etcconnect.com/fitco.html
-------------------------------------

Other Threads