點擊DBGrid標題怎麼實現對ADOQuery1查詢結果進行排序顯示啊?(50分)

  • 主题发起人 主题发起人 ygj971201
  • 开始时间 开始时间
Y

ygj971201

Unregistered / Unconfirmed
GUEST, unregistred user!
點擊DBGrid標題怎麼實現對ADOQuery1查詢結果進行排序顯示啊?
 
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
temp, title: string;
begin
temp := Column.FieldName;
qusp.Close;
if Column.Index <> lastcolumn then
begin
if (Pos('↑', DBGrid1.Columns[LastColumn].Title.Caption) > 0) or (Pos('↓', DBGrid1.Columns[LastColumn].Title.Caption) > 0) then
DBGrid1.Columns[LastColumn].Title.Caption := Copy(DBGrid1.Columns[LastColumn].Title.Caption, 3, Length(DBGrid1.Columns[LastColumn].Title.Caption) - 2);
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[Column.Index].Title.Caption := '↑' + DBGrid1.Columns[Column.Index].Title.Caption;
lastcolumn := column.Index;
end
else
begin
LastColumn := Column.Index;
title := DBGrid1.Columns[LastColumn].Title.Caption;
if Pos('↑', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' desc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↓' + title;
end
else if Pos('↓', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end
else
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end;
end;
qusp.Open;
end;
 
呵呵,拿分来~~~~
procedure TFData.DBGrid1TitleBtnClick(Sender: TObject; ACol: Integer;
Column: TColumnEh);
begin
if Adoquery1.Active then
if Trim(Copy(Adoquery1.Sort, length(Adoquery1.sort) - 4, 10)) =
'DESC' then
Adoquery1.sort := Column.Field.FieldName
else
Adoquery1.sort := Column.Field.FieldName + ' DESC'
end;
 
来自:pyk1, 时间:2006 :不行啊!
報錯:物件或提供者無法執行要求的操作
 
procedure TForm3.DBGrid1TitleClick(Column: TColumn);
begin
if pos('DESC', ADOQuery1.Sort) = 0 then
ADOQuery1.Sort := Column.Field.FieldName + ' DESC'
else
ADOQuery1.Sort := Column.Field.FieldName + ' ASC'
end;
 
不如用DBgridEh,又好用,并且支持N个列组合排序
 
后退
顶部