Data source is AdoQuery
1. First set the title-> titlebutton property of the field that needs to be sorted in DBGrideh, TRUE
2, set the Optionseh-> dbhautosortmarking properties of DGGrideh to TRUE
3. Judging in the OntitleButtonClick event in DBGRIDEH.
procedure Tfrmmain.dbgGridEh1TitleBtnClick (Sender: TObject; ACol: Integer; Column: TColumnEh); begin if column.Title.SortMarker = smdowneh then adoQuery1.Sort: = column.FieldName else adoQuery1.Sort: = column.FieldName 'DESC'; END;