Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting in a DBGrid from TQueries

Status
Not open for further replies.

LucieLastic

Programmer
May 9, 2001
1,694
GB
hi All

I'm using quite a few DBGrids in my app which are datasourced from TQueries. The database is SYBASE.

Like Outlook the user would like to be able to click on a column heading and the data will sort (switching between ASC and DESC).

I've got 3 ideas and wondering which to go for:-
1. Keep rewriting the ORDER BY in the query and accessing the database (the easiest).
2. Not sure if possible:- use indexing within a TTable, datasourced from my Tquery.
3. Program it all! - Using a TStringGrid in some way and loading this with the data from the query. Not sure how to sort in a column on a stringgrid though. Any tips grateful on this one.

So, any ideas on how I should tackle this? Development time isn't an issue really but the closest behaviour I can get to Outlook the better. Would like it to be pretty generic too.

Many thanks
lou
 
Using Indexes is ok unless you have millions of fields.

So, I would say that if you have very few fields then try Indexes otherwise I would use dynamic SQL and build the query with Order By's.
You can do it a little bit more intelligently by using a stored procedure which takes the column and ordering type and constructs the query internally. I do this with SQL server, by writing the entire generic portion of the query as a string and then dependant on the params passed tack on the Group By and the DESC if necessary. Then get SQL to EXEC the string query. Not sure if Sybase can do this but seeing as MSSQL is based on Sybase I would guess it can.

Forget StringGrid manipulation from DB data..it's just too much hassle. Get your DB engine to take the strain...that's why you paid loads of cash for it.
 
Thanks sjc

I've just found a component that does exactly what they want. It's by TMS Software and called TDBAdvStringGrid - they have some pretty good stuff in there.

Thanks for your help
lou
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top