Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Relational Databases
Expertise: Beginner
May 13, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning


How is possible to invert the order of a table display in a TDBGrid Component? Must it be an Index-DatabaseSource?

For example, if in the database was stored:


How is it possible to obtain this in a TDBGrid:

Of course, the last entry is the top-display in the component..

First of all, you can't do this on a TDBGrid. Keep in mind that that component is purely a display mechanism. Yes, it can be fairly sophisticated, but it's still a display mechanism. And while it may seem that switching the order of records is just like a display function, it's not. It's actually a function of the underlying table.

To achieve what you asked, assuming that this is a Paradox table (because I'm not sure about dBase tables), follow these steps:

  1. Open up the table the Database Desktop and restructure it.
  2. Drop the Table Properties field down and select "Secondary Indexes."
  3. Click the "Define" button and a new dialog box will pop up and display a list of fields. Click twice on the field you're interested in.
  4. At the bottom of the dialog box, check "Maintained" and "Descending."
  5. Click OK, then name the index when the input query box appears. Remember the name!
  6. Repeat this process with a new index, but do not check the "Descending" property. You want this to be a normal, Ascending index because you need to use it to get back to the original order.
  7. Save this index and name it.

Once you're armed with those two indexes, all you have to do is set the IndexName property of the underlying TTable by doing the following:

  1. Close the table.
  2. Set the index name.
  3. Activate the table.

and there you have it ... instant re-ordering!

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date