The data source is AdoQuery 1, first set the title-> titlebutton property of the field that needs to be sorted in DBGrideh, set the DGGrideh Optionseh-> DBHAUTOSORTMARKING attribute to True 3, which is judged in the dbgrideh OntitleButtonClick event. 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';