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 UniQuery1.Close; UniQuery1.SQL.Clear; UniQuery1.DisableControls; grdRateValue.DataSource:=nil; if column.Title.SortMarker=smDownEh then UniQuery1.SQL.Text:='select * from Ratevalue order by '+ column.FieldName +' ASC' else UniQuery1.SQL.Text:='select * from Ratevalue order by '+ column.FieldName +' DESC'; UniQuery1.Open; UniQuery1.EnableControls; form1.Caption:= UniQuery1.RecordCount.ToString; grdRateValue.DataSource:=Datasource1; end; end.
标签:end,DBGridEh,标题栏,TForm1,grdRateValue,lazarus,SQL,UniQuery1,UniConnection1 From: https://www.cnblogs.com/qiufeng2014/p/18395412