Re: DBGrid Sort by Column Click at Runtime.

[ Delphi Forum -- by DelphiLand ]

Posted by webmaster Guido on January 08, 2004 at 16:30:35:

In Reply to: DBGrid Sort by Column Click at Runtime. posted by Syed Ashfaq on January 02, 2004 at 07:31:15:

: I have a problem with Sorting DBGrid by Column Click which holds a table control.But this table control does not have a sort property becoz i m using a customized component.
: I can sort the DBgrid using the following code:
: Ttable(column.field.dataset).IndexFieldNames:=column.FieldName;

: But this only sorts Ascending ,but i need Descending Sort as well.


As far as I know, a table control never has a "sort" property. You have to indicate which *index* you want to use with the table, and the table will be accessed in the order that is defined by the index file.

So, with your code you do not "sort the DBGrid", but you tell the table component which index to use. The order in which records are shown in a DBGrid depends from how the table's index was built: ascending, descending, or even a combination of several fields. This has nothing to do with the kind of component you use.

[ Delphi Forum ]
[ DelphiLand: free Delphi source code, tips, tutorials ]