DBGRID Click the title automatic sort

xiaoxiao2021-04-07  334

procedure TForm1.DBGrid1TitleClick (Column: TColumn); var s, cFieldName: string; i: integer; DataSet: TDataSet; begin Try DataSet: = Column.Grid.DataSource.DataSet; if not DataSet.Active then exit; if Column.Field .FieldKind = fkLookup then cFieldName: = Column.Field.KeyFields else if Column.Field.FieldKind = fkCalculated then cFieldName: = Column.Field.KeyFields else cFieldName: = Column.FieldName; if DataSet is TCustomADODataSet then begin s: = TCustomADODataSet ( Dataset; if s = '' Then Begin s: = cfieldname; Else Begin if Pos (CfieldName, S) <> 0 THEN BEGIN I: = POS ('dec', s); if i <= 0 THEN Begin S: = S 'DESC'; END ELSE BEGIN Delete (ELSE BEGIN S: = CfieldName; end; end; tcustomadodataset (dataset) .sort: = s; Else if DataSet IS TClientDataSet then begin if TClientDataSet (DataSet) .indexfieldnames <> '' then begin i: = TClientDataSet (DataSet) .IndexDefs.IndexOf ( 'i' Column.FieldName); if i = -1 then begin with TClientDataSet (DataSet). Indexdefs.addIndexdef Do Begin Name: = 'i' column.fieldName; Fields: = Column.FieldName; DescFields: = Column.FieldName; end; end; TClientDataSet (DataSet) .IndexFieldNames: = ''; TClientDataSet (DataSet) .IndexName: = 'i' Column.FieldName; end else begin TClientDataSet (DataSet). IndexName: = '; tclientDataSet (Dataset) .indexfieldnames: = column.fieldname; end; end; except end;

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

New Post(0)