Z
Zach
In the code below, where indicated error 1, I get this error message: Error
1 using the generic type 'System.Collections.Generic.IComparer<T>' requires
'1' type arguments.
What I really want to do is use CODE, WITHOUT MANUALLY selecting column
three, to sort column three, and get the rest of listview in column three
order.
Could s.o. please tell me what to do?
Many thanks,
Zach.
#region Sorting columns.
// Implements the manual sorting of items by columns.
class ListViewItemComparer : IComparer <------- error 1
{
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);
}
}
// ColumnClick event handler.
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();
}
#endregion
1 using the generic type 'System.Collections.Generic.IComparer<T>' requires
'1' type arguments.
What I really want to do is use CODE, WITHOUT MANUALLY selecting column
three, to sort column three, and get the rest of listview in column three
order.
Could s.o. please tell me what to do?
Many thanks,
Zach.
#region Sorting columns.
// Implements the manual sorting of items by columns.
class ListViewItemComparer : IComparer <------- error 1
{
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);
}
}
// ColumnClick event handler.
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();
}
#endregion