我用DBGridEh1做排序,写如下代码,还要在DBGridEh1中设置什么属性,才能使他排序?(0分)

  • 主题发起人 主题发起人 wangchengwu
  • 开始时间 开始时间
W

wangchengwu

Unregistered / Unconfirmed
GUEST, unregistred user!
我用DBGridEh1做排序,写如下代码,还要在DBGridEh1中设置什么属性,才能使他排序?

procedure TForm1.DBGridEh1SortMarkingChanged(Sender: TObject);
var i :Integer;
s:String;
function DeleteStr(str:String; sunstr:String): String;
var i:Integer;
begin
i := Pos(sunstr,str);
if i <> 0 then Delete(str,i,Length(sunstr));
Result := str;
end;
begin
s := '';
for i := 0 to DBGridEh1.SortMarkedColumns.Count-1 do
if DBGridEh1.SortMarkedColumns.Title.SortMarker = smUpEh then
s := s + DBGridEh1.SortMarkedColumns.FieldName + ' DESC , '
else
s := s + DBGridEh1.SortMarkedColumns.FieldName + ', ';
if s <> '' then s := ' ORDER BY ' + Copy(s,1,Length(s)-2);
s := DeleteStr(s,'1');
AQ_DBGridEh1.SQL.Strings[AQ_DBGridEh1.SQL.Count-2] := s;
AQ_DBGridEh1.Close;
AQ_DBGridEh1.Open;
end;






procedure TForm1.DBGridEh1TitleBtnClick(Sender: TObject; ACol: Integer;
Column: TColumnEh);
begin
case Column.Title.SortMarker of
smNoneEh: Column.Title.SortMarker := smDownEh;
smDownEh: Column.Title.SortMarker := smUpEh;
smUpEh: Column.Title.SortMarker := smNoneEh;
end;
end;
 
dataset.order := '字段名'
即可
 
用ADO,好办。
代码如下:(我用的是:EHLIB25)
procedure TForm1.DBGridEh1TitleClick(Column: TColumnEh);
begin
if DBGridEh1.DataSource.DataSet.IsEmpty then Exit;
case Column.Title.SortMarker of
smNoneEh:
begin
Column.Title.SortMarker := smDownEh;
(DBGridEh1.DataSource.DataSet as TADOQuery).Sort := column.fieldname + ' DESC';
end;
smDownEh:
begin
Column.Title.SortMarker := smUpEh;
(DBGridEh1.DataSource.DataSet as TADOQuery).Sort := column.fieldname + ' ASC';
end;
smUpEh:
begin
Column.Title.SortMarker := smNoneEh;
(DBGridEh1.DataSource.DataSet as TADOQuery).Sort := '';
end;
end;
end;
 
接受答案了.
 
后退
顶部