lazarus DBGridEh标题栏排序
按网上(delphi)的方法发现无效,经测试,以下代码可以正常排序:
按网上(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 then //注意:smDownEh要在uses添加ToolCtrlsEh UniQuery1.IndexFieldNames:=column.FieldName +' ASC' else UniQuery1.IndexFieldNames:=column.FieldName +' DESC'; end; end.