ListViewSort question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adrian

    ListViewSort question


    Using the code below, I get this error.

    Using the generic type 'System.Collect ions.Generic.IC omparer<T>' requires
    '1' type arguments

    Please tell me how to put this right.

    Adrian.




    // Implements the manual sorting of items by columns.

    class ListViewItemCom parer : IComparer
    {
    private int col;
    public ListViewItemCom parer()
    {
    col = 0;
    }
    public ListViewItemCom parer(int column)
    {
    col = column;
    }
    public int Compare(object x, object y)
    {
    return String.Compare( ((ListViewItem) x).SubItems[col].Text,
    ((ListViewItem) y).SubItems[col].Text);
    }
    }

    // ColumnClick event handler.
    private void ColumnClick(obj ect o, ColumnClickEven tArgs e)
    {
    // Set the ListViewItemSor ter property to a new
    ListViewItemCom parer object.
    this.listView1. ListViewItemSor ter = new
    ListViewItemCom parer(e.Column) ;
    // Call the sort method to manually sort the column based on the
    ListViewItemCom parer implementation.
    listView1.Sort( );
    }


  • Claes Bergefall

    #2
    Re: ListViewSort question

    I can only guess that the compiler thinks you're refering to
    System.Collecti ons.Generic.ICo mparer when you write IComparer. Do you have a
    using System.Collecti ons.Generic; statement at the top by any chance? Try
    using the full name (i.e. System.Collecti ons.IComparer)

    /claes


    "Adrian" <00@00.00wrot e in message
    news:44f6b04c$0 $745$5fc3050@dr eader2.news.tis cali.nl...
    >
    Using the code below, I get this error.
    >
    Using the generic type 'System.Collect ions.Generic.IC omparer<T>' requires
    '1' type arguments
    >
    Please tell me how to put this right.
    >
    Adrian.
    >
    >
    >
    >
    // Implements the manual sorting of items by columns.
    >
    class ListViewItemCom parer : IComparer
    {
    private int col;
    public ListViewItemCom parer()
    {
    col = 0;
    }
    public ListViewItemCom parer(int column)
    {
    col = column;
    }
    public int Compare(object x, object y)
    {
    return String.Compare( ((ListViewItem) x).SubItems[col].Text,
    ((ListViewItem) y).SubItems[col].Text);
    }
    }
    >
    // ColumnClick event handler.
    private void ColumnClick(obj ect o, ColumnClickEven tArgs e)
    {
    // Set the ListViewItemSor ter property to a new
    ListViewItemCom parer object.
    this.listView1. ListViewItemSor ter = new
    ListViewItemCom parer(e.Column) ;
    // Call the sort method to manually sort the column based on
    the
    ListViewItemCom parer implementation.
    listView1.Sort( );
    }
    >
    >

    Comment

    Working...