双击dbgrid排序的问题

有关双击dbgrid排序的问题(想让用户双击dbgird控件的某一个字段时就升序,再双击就降序....?)【DFW:DouZheng】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;

原文地址:https://www.cnblogs.com/martian6125/p/9631541.html