CLIENTDATASET with DBGRID to click on the title to sort

xiaoxiao2021-04-07  341

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.

转载请注明原文地址:https://www.9cbs.com/read-132391.html

New Post(0)