Sort when you click the title bar in DBGRID

zhaozj2021-02-17  46

method:

The key is to use DBGRID event ontitleclick

First, judge which column is,

i: = column.index;

Then determine which field is it?

Field: = dbgrid1.columns [i] .fieldname 'ASC';

Finally, sort:

QRYWORK.SORT: = Field;

The above is just ascending order, to add descending order, use 'dec'

To click, ascending, then click, descend the order .....

Use a parity judgment

An example of me

(Where Bsort: Boolean, initialization when FormShow)

procedure TfmPlayVideo.DBGrid1TitleClick (Column: TColumn); var i: integer; fieldname: string; begin // Sort i: = Column.Index; if bSort then begin fieldname: = DBGrid1.Columns [i] .FieldName 'ASC'; bSort : = False; Else Begin FieldName: = dbgrid1.columns [i] .fieldname 'dec'; bsort: = true; end; QRYSHOW.SORT: = FIELDNAME; END;

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

New Post(0)