Click the title of DBGrid to sort the query results.

Source: Internet
Author: User
// Click the title of DBGrid to sort the query results. If you want to use a common program, it is not a matter of discussion,
// When you click another title, you need to sort it in another order to do whatever you like the resource manager.
Procedure tform5.dbgrd1titleclick (column: tcolumn );
VaR
Myfieldname: string;
Begin
If not (column. Field. fieldkind in [fkdata, fklookup]) Then exit;
If column. Field. fieldkind = fkdata then
Myfieldname: = uppercase (column. Field. fieldname)
Else
Myfieldname: = uppercase (column. Field. keyfields );
While pos (myfieldname, ';') <> 0 do
Myfieldname: = copy (myfieldname, 1, pos (myfieldname, ';')-1)
+ ',' + Copy (myfieldname, pos (myfieldname, ';') + 1,100); // change ";" ","
With tadoquery (TDBGrid (column. Grid). datasource. dataset) Do
Begin
If column. Field. Tag = 0 then
Begin
Sort: = myfieldname + 'asc ';
Column. Field. Tag: = 1;
End
Else
Begin
Sort: = myfieldname + 'desc ';
Column. Field. Tag: = 0;
End;
End;
End;
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.