Sort DBGrid by clicking column's title

Eliseo Ocampos picture Eliseo Ocampos · Jul 17, 2009 · Viewed 22.1k times · Source

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

The thing is that I'm (sadly) working with Delphi 3, 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?

Answer

Mason Wheeler picture Mason Wheeler · Jul 18, 2009

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.