Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I order a DBGrid using a TTable

Status
Not open for further replies.

john230873

Programmer
Oct 3, 2003
89
NZ
Hi I am using 2 TTables one is a master and the second is a detail. I have the detail showing in a DBgrid and is linked to the master by the Primary index. When I enter in a new product it puts it to the top of the DBgrid, I want it at the bottom. How do I change the order of the detail table, I have tried changing the index but that just upsets the master-detail link and no records are showen.

 
Suppose your TTable components are called Master and Detail. Suppose the index field you want to link on is called MID in the Master and DID in the Detail table.

The Detail table should have at least two columns in its primary index. The first one will be DID. For the purpose of this example, the second one will be called SEQ.

The Detail should be linked to the Master by setting the following properties:

Detail.IndexFieldNames to DID
Detail.MasterFields to MID

You should now find that when you add a record to the Detail table it will be displayed in the TDBGrid in the order indicated by SEQ. It's up to you to assign a suitable value to SEQ but this can be made automatic by using an auto_increment field.

Andrew
Hampshire, UK
 
Another solution you might try - given the specifics of your questions - is to add a secondary index to the detail table and link on that index instead of the table's primary. Depending on the database you're using, you might create a descending index with (from Andrew's example) the linking key plus the sequence number. This solution would reverse the order of the detail records without your having to change the assigment of your detail record key values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top