Re: List View Sorting Question

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I see that you are trying to compare ListViewItems as Strings, so you need
to specify the string type as a generic type parameter:

class ListViewItemComparer : IComparer< string>

and you need to declare the Compare method with string as parameter type:

public int Compare(string x, string y)


"> Adrian <" <x@xxxxx> wrote in message
news:45e59e38$0$721$5fc3050@xxxxxxxxxxxxxxxxxxxxxxxxxxx
In VS 2003 I could sort a column in a list view using the code below,
hover, in V2005 I get this error:
Error 1 Using the generic type 'System.Collections.Generic.IComparer<T>'
requires '1' type arguments

What to do?

Please tell me concretely how to get rid of this error in terms of code.

Many thanks,
Adrian

private void ColumnClick(object o, ColumnClickEventArgs e)
{
// Set the ListViewItemSorter property to a new
ListViewItemComparer object.
this.listView1.ListViewItemSorter = new
ListViewItemComparer(e.Column);
// Call the sort method to manually sort the column based on
the
ListViewItemComparer implementation.
listView1.Sort();
}


// Implements the manual sorting of items by columns.
class ListViewItemComparer : IComparer ****error line***
{
private int col;
public ListViewItemComparer()
{
col = 0;
}
public ListViewItemComparer(int column)
{
col = column;
}
public int Compare(object x, object y)
{
return String.Compare(((ListViewItem)x).SubItems[col].Text,
((ListViewItem)y).SubItems[col].Text);
}
}








.