只可以对第一项进行排序,如果要使用后面的项目进行排序只能在ListViewColumnClick,ListViewCompare 事件中添加代码!

解决方案 »

  1.   

    在ListView1ColumnClick,ListView1Compare 事件中添加代码!
      

  2.   

    在ListViewColumnClick,ListViewCompare 事件中添加代码!
      

  3.   

    var ColumnToSort: Integer;The OnColumnClick event handler sets the global variable to indicate the column to sort and calls AlphaSort:procedure TForm1.ListView1ColumnClick(Sender: TObject; Column: TListColumn);begin
      ColumnToSort := Column.Index;
      (Sender as TCustomListView).AlphaSort;
    end;
    The OnCompare event handler causes the list view to sort on the selected column:procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
    var
      ix: Integer;
    begin
      if ColumnToSort = 0 then
        Compare := CompareText(Item1.Caption,Item2.Caption)
      else begin
       ix := ColumnToSort - 1;
       Compare := CompareText(Item1.SubItems[ix],Item2.SubItems[ix]);
      end;end;
      

  4.   

    我正在用的。function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
    implementation//之前定义上面这句procedure TForm1.ListView1ColumnClick(Sender: TObject;
      Column: TListColumn);
    begin
      ListData.CustomSort(@CustomSortProc, Column.Index);
    end;function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
    begin
      if ParamSort>0 then
        Result := CompareText(Item1.SubItems.Strings[ParamSort-1],Item2.SubItems.Strings[ParamSort-1])
      else
        Result := CompareText(Item1.Caption,Item2.Caption);
    end;