dbgrid 如何实现排序箭头(三角的)
dbgrid 如何实现排序箭头(三角的)
[解决办法]
首先申明是从网上贴的(原来粘下来的,不知道原创人了:( ),不是原创,呵呵,
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;