views:

532

answers:

3

Well, this seems a little tricky (if not imposible). I'm tryin to make my DBGrid sort its data by clicking on column's title.

The thing is that I'm (sadly) working with Delphi3, I'm not using ADO DataSets and the query gets a lot of rows, thus I can't reopen my TQuery changing the "order by" clause on clicks.

Someone has implemented something like this?

+3  A: 

This is actually done by sorting the dataset, and then the grid reflects the change. It can be done easily enough by creating an index on the dataset field for that column. Of course, this can only be done on a dataset that supports index sorting, such as TClientDataset.

Mason Wheeler
A: 

Delphi 3 have TClientDataset. And TQuery can use explicitly created indexes on the database to order data on the IndexName property.

Fabricio Araujo
Not necessarily true, neither my Delphi 4 Pro nor my Delphi 5 Pro installation have TClientDataSet. Maybe it's only in the Enterprise version?
mghie
Hmmm. On these versions I only touched Enterprise editions (since I normally worked in loco). But D3 Enterprise certainly have TClientDataset.
Fabricio Araujo
A: 

There are some examples of how to do this Here. As already mentioned, sorting is quite easy if you are using a TClientDataSet (cds.IndexFieldNames := Column.FieldName in the OnTitleClick of the TDBGrid). However if you are not able to do this you can either regenerate your query (which you have stated you don't want to do) or obtain a more advanced data grid such as Express Quantum Grid (which I think allows you to sort).

Alister