Jump to content
ChrisChuah

DBGrid sort descending on Column Title Click

Recommended Posts

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

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
Posted (edited)

hi

Thanks. I will use the AddIndex function to do the sorting.

 

regards

chris

Edited by ChrisChuah

Share this post


Link to post

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×