Use the DBGRID control to match the sort properties of the data set component to "click the title bar automatic sorting fun

xiaoxiao2021-03-06  37

Many friends are complaining when using the DBGRID control, the function that can be automatically sorted without clicking on the title bar. It actually cooperates with the ONTITLICLICK event of DBGRID through the Sort property of AdoQuery or other data set components. This feature can be easily implemented. Because sort properties can be sorted by the specified fields, you can also select the sort mode (ascending / descending order), so we can set the sort field and sort mode in the Ontitleclick event, as follows: Procedure TFORM1.DBGRID1TITLECLICK (Column: tcolumn); var i: integer; begin for i: = 1 to dbgrid1.columns.count do begin // Restore all title fonts for default dbgrid1.columns [i-1] .title.font.color: = CLWINDOWText DBGRID1.COLUMNS [I-1] .title.font.style: = []; end; if adoquery1.sort <> (column.fieldname 'ASC') THEN / / Judgment Original Sort by Begin AdoQuery1.Sort: = Column .Fieldname 'ASC'; column.title.font.color: = CLRED; // Changing the title line font is red, indicating the current sort mode to ascending column.title.font.style: = [fsbold]; Else Begin AdoQuery1 .Sort: = column.fieldname 'desc'; column.title.font.color: = CLBLUE; // Changing the title line font is red, indicating the current sorting method is descending order column.Title.Font.Style: = [fsbold] END; END; December 20, 2004

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

New Post(0)