Board index » delphi » DBGrid - Post Event forces Inserted record to bottom. Help!

DBGrid - Post Event forces Inserted record to bottom. Help!

Whenever I insert a record into a DBGrid component , as soon as I
move off the record (which forces a post event) the inserted record
drops to the bottom of the DBGrid. How can I prevent this so I can keep the
table in the order that I want. Help Appreciated.

 

Re:DBGrid - Post Event forces Inserted record to bottom. Help!


Whenever I insert a record into a DBGrid component , as soon as I
move off the record (which forces a post event) the inserted record
drops to the bottom of the DBGrid. How can I prevent this so I can keep the
table in the order that I want. Help Appreciated.

Re:DBGrid - Post Event forces Inserted record to bottom. Help!


The records are sorted according to  the current index. Are you using an
autoincrement field as the primary key?. In this situation if you do not
select another index for the TTable, new records will always go to the end
of the grid.

Re:DBGrid - Post Event forces Inserted record to bottom. Help!


Quote
Jeffrey Ottery <jott...@yarra.vicnet.net.au> wrote:
>Whenever I insert a record into a DBGrid component , as soon as I
>move off the record (which forces a post event) the inserted record
>drops to the bottom of the DBGrid. How can I prevent this so I can keep the
>table in the order that I want. Help Appreciated.

Delphi sorts it's records based on the active index.
If You haven't set the IndexName-property to anything,
it will sort on the "hidden" primary index.

Dag

Re:DBGrid - Post Event forces Inserted record to bottom. Help!


Quote
Jeffrey Ottery wrote:

> Whenever I insert a record into a DBGrid component , as soon as I
> move off the record (which forces a post event) the inserted record
> drops to the bottom of the DBGrid. How can I prevent this so I can keep the
> table in the order that I want. Help Appreciated.

Create the index for the field you want the records to order by, and set
the IndexName property of the TTable. See FishFact demo in DEMOS\DB.

--
-------------------------------------
Robert Cerny - application designer & developer
Neosys Ltd. Ljubljana
Email: robert.ce...@neosys.xrs.si

Other Threads