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:
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:
- Open up the table the Database Desktop and restructure it.
- Drop the Table Properties field down and select “Secondary Indexes.”
- 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.
- At the bottom of the dialog box, check “Maintained” and “Descending.”
- Click OK, then name the index when the input query box appears. Remember the name!
- 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.
- 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:
- Close the table.
- Set the index name.
- Activate the table.
and there you have it … instant re-ordering!