By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,926 Members | 1,839 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,926 IT Pros & Developers. It's quick & easy.

List View Sorting Question

P: n/a
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);
}
}


Feb 28 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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@xx.xxwrote in message
news:45********************@dreader2.news.tiscali. nl...
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);
}
}


Feb 28 '07 #2

P: n/a
The solution was simple after all.
Thank you guys.
Adrian
---
"Adrian <" <x@xx.xxwrote in message
news:45********************@dreader2.news.tiscali. nl...
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);
}
}


Mar 1 '07 #3

P: n/a
Sorry people, this went the worng way.
Adrian.
"Adrian <" <x@xx.xxwrote in message
news:45********************@dreader2.news.tiscali. nl...
The solution was simple after all.
Thank you guys.
Adrian
---
"Adrian <" <x@xx.xxwrote in message
news:45********************@dreader2.news.tiscali. nl...
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);
}
}




Mar 1 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.