ChrisChuah 0 Posted June 25 Hi I am using TSQLQuery, TClientDataSet and TDataSetProvider with DBGrid If i want to sort the DBGrid based on title column click, i can use the event OnTitleClick on DBGrid ClientDataSet.IndexFieldsName := Column.FieldName However, this will sort the Field in ascending order. How can i sort it in descending order? please advise regards chris Share this post Link to post
Lajos Juhász 126 Posted June 25 In that case you use the AddIndex merhod. For more information: https://docwiki.embarcadero.com/Libraries/Sydney/en/Datasnap.DBClient.TCustomClientDataSet.AddIndex here you can find a helper procedure https://edn.embarcadero.com/article/29056 to sort. 1 Share this post Link to post
bazzer747 15 Posted June 25 if Grd.IndexFieldNames = Column.FieldName then fGrd.IndexFieldNames:= Column.FieldName + ':D' else Grd.IndexFieldNames:= Column.FieldName; end; ..The :D reverses the sort. Share this post Link to post
Dmitry Arefiev 82 Posted June 25 ':D' is not supported by TClientDataSet ... Share this post Link to post
ChrisChuah 0 Posted July 1 (edited) hi Thanks. I will use the AddIndex function to do the sorting. regards chris Edited July 1 by ChrisChuah Share this post Link to post
ChrisChuah 0 Posted July 2 Hi I have another question. After i use the AddIndex and set the IndexName to the index field created, how can i get back the information of what index field is used and what is the sorting order (asc or desc) e.g. l_indexName := 'ABN_REM' + '_INDEX'; l_indexes := TStringList.create; (TntDBGrid1.DataSource.DataSet as TClientDataSet).GetIndexNames(l_indexes); if l_indexes.IndexOf(l_indexName) > -1 then (TntDBGrid1.DataSource.DataSet as TClientDataset).DeleteIndex(l_indexName); l_indexes.Free; (TntDBGrid1.DataSource.DataSet as TClientDataset).AddIndex(l_indexName, 'FREE_REM', [ixDescending],'','',0 ); (TntDBGrid1.DataSource.DataSet as TClientDataset).IndexName := l_indexName; In the above code, i have set the IndexName to 'ABN_REM_INDEX' with field 'FREE_REM' used and sort in descending order. So, how can i get back this information that the field name 'FREE_REM' is used and the sorting is in descending order? regards chris Share this post Link to post