简体   繁体   English

如何在delphi 7中对dbgrid进行数据排序

[英]how to sort data on a dbgrid in delphi 7

hello i am new to zeos datasets and i would like my db grid to sort the data in an ascending or descending mode. 您好我是zeos数据集的新手,我希望我的数据库网格以升序或降序模式对数据进行排序。 i am using zeos datasets and a firebird database. 我正在使用zeos数据集和firebird数据库。 i tried searching and this is all i got 我试着搜索,这就是我得到的

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
{$J+}
 const PreviousColumnIndex : integer = -1;
{$J-}
begin
  if DBGrid1.DataSource.DataSet is TCustomADODataSet then
  with TCustomADODataSet(DBGrid1.DataSource.DataSet) do
  begin
    try
      DBGrid1.Columns[PreviousColumnIndex].title.Font.Style :=
      DBGrid1.Columns[PreviousColumnIndex].title.Font.Style - [fsBold];
    except
    end;

Column.title.Font.Style := 
Column.title.Font.Style + [fsBold];
PreviousColumnIndex := Column.Index;

if (Pos(Column.Field.FieldName, Sort) = 1)
and (Pos(' DESC', Sort)= 0) then
  Sort := Column.Field.FieldName + ' DESC'
else
  Sort := Column.Field.FieldName + ' ASC';
  end;
end;

this was from another site but problem is i cant figure out how to use it to the zeos dataset. 这是来自另一个网站,但问题是我无法弄清楚如何将它用于zeos数据集。 this is by far what i got 到目前为止,这是我得到的

procedure Tdc.DBGrid1TitleClick(Column: TColumn);
begin
      with TZtable (DBGrid1.DataSource.DataSet) do
  Sort := Column.Field.FieldName; + ' ASC'
end;

but frankly i have no idea where to start 但坦率地说,我不知道从哪里开始

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
  st:ZAbstractRODataset.TSortType;
begin
  st:=ZReadOnlyQuery1.SortType;
  ZReadOnlyQuery1.SortedFields:=Column.FieldName;
  If st = stAscending then ZReadOnlyQuery1.SortType:=stDescending else ZReadOnlyQuery1.SortType:=stAscending;
  DataSource1.DataSet.First;
end;

@bummi thank you @bummi谢谢你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM