你好我是zeos数据集的新手,我希望我的数据库网格以升序或降序模式对数据进行排序。我正在使用zeos数据集和firebird数据库。我试着搜索,这就是我得到的全部
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;
这是来自另一个网站,但问题是我无法弄清楚如何将它用于zeos数据集。到目前为止,这是我得到的
procedure Tdc.DBGrid1TitleClick(Column: TColumn);
begin
with TZtable (DBGrid1.DataSource.DataSet) do
Sort := Column.Field.FieldName; + ' ASC'
end;
但坦率地说我不知道从哪里开始
答案 0 :(得分:2)
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谢谢你