Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Thread Tools Display Modes
Old 01-01-2002, 06:51 AM
heddock heddock is offline
Senior Member
Join Date: Mar 2001
Posts: 124
Default How to sort a db grid and stringgrid

Hello guys,

i want to sort a dbgrid or stringgrid if the user clicks on the header of the column. How can i do that. I'm using kadao database with dbgrids and the normally delphi6 stringgrids.

Tnx in advance


To Go Where nobody has gone before
Reply With Quote
Old 01-01-2002, 07:44 AM
I.Ivanov I.Ivanov is offline
Senior Member
Join Date: Dec 2001
Posts: 166
Default RE: How to sort a db grid and stringgrid

Hello, Heddock!

1) TStringGrid can be sorted only manually (if you will add information in Cells array in right order, using QSort for example "D:\Program Files\Borland\Delphi.5_5\Demos\Threads\").
2) DBGrid can not be sorted. You can only use Indexname,IndexFieldNames property of TTable, TQuery object assigned to DBGrid by TDatasource. But then you should create all indexes for all fields (ascending and descending if you want to sort in both directions).
I know only one db engine which has all needed ascending indexes always - EasyTable,


procedure TMainForm.OpenGridTitleClick(Column: TColumn);
// if index name = field name
CurrentTable.IndexName := Column.FieldName;
// for EasyTable it looks like:
CurrentTable.IndexName := '@'+Column.FieldName;

But in both cases mentioned above you can not add picture to Grid column header (like arrows up, down).

3) Easiest way (but not fastest, as grids usually not uses indexes of db engine, and this leads to lower performane) to do all that is use third party components:


DBAltGrid by Quasidata

TCoolGrid -

AdvStringGrid by TMS Software


EtvLibrary -

Happy New Year to all!

If I helped, please click 'Accept as Answer'. Thanks.

Best regards,
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 12:09 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.