秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  278 随笔 :: 0 文章 :: 308 评论 :: 20万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
lazarus DBGridEh标题栏排序
按网上(delphi)的方法发现无效,经测试,以下代码可以正常排序:
复制代码
unit Unit1;

{$mode ObjFPC}{$H+}

interface

uses
  Classes, SysUtils, DB, Forms, Controls, Graphics, Dialogs, StdCtrls, Uni,
  DBGridsEh, DBCtrlsEh, LConvEncoding, DBGridEhImpExp, lclintf, DBGrids,
  ToolCtrlsEh;

type

  { TForm1 }

  TForm1 = class(TForm)
    DataSource1: TDataSource;
    grdRateValue: TDBGridEh;
    UniConnection1: TUniConnection;
    UniQuery1: TUniQuery;
    procedure FormCreate(Sender: TObject);
    procedure grdRateValueTitleBtnClick(Sender: TObject; ACol: Integer;
      Column: TColumnEh);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var i,j:integer;
begin
  if UniConnection1.Connected then UniConnection1.Connected:=False;
  UniConnection1.ProviderName:='SQLite';
  with UniConnection1 do
  begin
    Database:=ExtractFilePath(Application.ExeName)+'db';
    SpecificOptions.Values['ClientLibrary']:=UTF8ToCP936(ExtractFilePath(Application.ExeName))+'sqlite3_x64.dll';
    SpecificOptions.Values['useunicode']:='True';
    Connected:=True;
  end;
  if UniQuery1.Active then UniQuery1.Close;
  UniQuery1.SQL.Clear;
  UniQuery1.SQL.Add('select * from Ratevalue   order by rate  DESC');
  UniQuery1.Open;
  grdRateValue.OptionsEh:= [dghAutoSortMarking, dghMultiSortMarking];
  i:=grdRateValue.Columns.Count;
  for j:=0 to i-1 do
    grdRateValue.Columns[j].Title.TitleButton := True;
  grdRateValue.OnTitleBtnClick := @grdRateValueTitleBtnClick;
end;

procedure TForm1.grdRateValueTitleBtnClick(Sender: TObject; ACol: Integer;
  Column: TColumnEh);
begin
  if (column.Title.SortMarker=smDownEh) or (column.Title.SortMarker=smNoneEh) then //注意:smDownEh要在uses添加ToolCtrlsEh
     UniQuery1.IndexFieldNames:=column.FieldName +' ASC'
  else
     UniQuery1.IndexFieldNames:=column.FieldName +' DESC';
end;

end.
复制代码

 

posted on   秋·风  阅读(173)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示