DBGRID标题排序上放↑

DBGRID标题排序上放↑


 

procedure TF_StockReport.FlatDBGrid1TitleClick(Column: TColumn);
var
  TheTitleName:string;
begin
  if DM.GoodsInfo.IsEmpty then Exit;
  TheTitleName:=Column.Title.Caption;
  if Pos('↑',TheTitleName)>0 then  begin
     DM.GoodsInfo.SQL.Clear;
     DM.GoodsInfo.SQL.Add('Select * From 商品信息 Order By '+StringReplace(TheTitleName,'↑','',[rfReplaceAll]));
     DM.GoodsInfo.Open;
     Column.Title.Caption:=StringReplace(Column.Title.Caption,'↑','↓',[rfReplaceAll]);
  end;
  if Pos('↓',TheTitleName)>0 then  begin
     DM.GoodsInfo.SQL.Clear;
     DM.GoodsInfo.SQL.Add('Select * From 商品信息 Order By '+StringReplace(TheTitleName,'↓','',[rfReplaceAll])+' DESC');
     DM.GoodsInfo.Open;
     Column.Title.Caption:=StringReplace(Column.Title.Caption,'↓','↑',[rfReplaceAll]);
  end;
end;
------------------------------------------------------------------------------------

你可能感兴趣的:(grid)