devxlogo

TDBGrid

TDBGrid

Question:
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:

1Pippo
2Gino
3Pluto

How is it possible to obtain this in a TDBGrid:

3Pluto
2Gino
1Pippo
Of course, the last entry is the top-display in the component..

Answer:
First of all, you can’t do this on a TDBGrid. Keep in mind that thatcomponent is purely a display mechanism. Yes, it can be fairlysophisticated, but it’s still a display mechanism. And while it may seemthat switching the order of records is just like a display function, it’snot. It’s actually a function of the underlying table.

To achieve what you asked, assuming that this is a Paradox table (becauseI’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 alist 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 youneed 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 theIndexName 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!

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist