var ASC: Boolean; // whether ascending procedure TForm1.DsSort (SortColumn: TColumn); var OldIndex: string; begin if (SortColumn.Grid.DataSource = nil) or (SortColumn.Grid.DataSource.DataSet = nil) or ( not SortColumn.Grid.DataSource.DataSet.Active) then Exit; oldIndex: = TClientDataSet (SortColumn.Field.DataSet) .IndexName; if oldIndex <> '' then begin TClientDataSet (SortColumn.Field.DataSet) .IndexName: = '' ; TClientDataSet (SortColumn.Field.DataSet) .DeleteIndex (oldIndex); end; case ASC of True: TClientDataSet (SortColumn.Field.DataSet) .AddIndex ( 'px', SortColumn.Field.FieldName, [ixDescending]); // It is already an ascending order to arrange the else // otherwise tclientDataSet (SortColumn.field.DataSet) .addindex ('px', sortcolumn.field.fieldname, [ixprimary]); end; {end case} tclientDataSet (SortColumn); Field.dataset) .indexName: = 'PX'; asc: = not asc; end; call procedure tform1.dbgrd1titleclick (Column: tcolumn); Begin Dssort (Column); end; this method is from netizen's blog , Just use it, it is easy to use.