写listview的OnCompare事件, 在那里自己定义顺序delphi自带有正例子,你再把+1,-1对调
就是反排序了

解决方案 »

  1.   

    自己写CustomSortProc函数,
    以下是我写的一个例子, 单击ListView的Column可正反排序var m_bSort: boolean=false;
    //...........//回调函数
    function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
    var txt1,txt2 : string;
    begin
      if ParamSort <> 0 then begin
          txt1 := Item1.SubItems.Strings[ParamSort - 1];
          txt2 := Item2.SubItems.Strings[ParamSort - 1];      if m_bSort then begin //这个变量来控制正反排序
             Result := CompareText(txt1,txt2);
          end else begin
             Result := -CompareText(txt1,txt2);
          end;
      end else begin
          if m_bSort then begin
             Result := CompareText(Item1.Caption,Item2.Caption);
          end else begin
             Result := -CompareText(Item1.Caption,Item2.Caption);
          end;
      end;
    end;procedure TForm1.ListView1ColumnClick(Sender: TObject;
      Column: TListColumn);
    begin
      ListView1.CustomSort(@CustomSortProc, Column.Index);
      m_bSort := not m_bSort;
    end;