From: Zach on 21 Apr 2010 11:00 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
From: Harlan Messinger on 21 Apr 2010 11:13 Zach wrote: > 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. Right. The type name is IComparer<T>, not IComparer, as you have it. You can either implement this for a specific type, as in: class ListViewItemComparer : IComparer<string> { public int Compare(string x, string y) ... or you can make your implementing class generic: class ListViewItemComparer<T> : IComparer<T> { public int Compare(T x, T y) ... depending on which of these represents what you are trying to accomplish. [snip] > #region Sorting columns. > // Implements the manual sorting of items by columns. > > class ListViewItemComparer : IComparer <------- error 1 > { [snip]
From: Peter Duniho on 21 Apr 2010 11:22 Zach wrote: > 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. Just as the error is explaining to you, the use of the System.Collections.Generic.IComparer<T> type requires one type argument. You haven't provided one. If you want to implement System.Collections.IComparer instead, then either don't put "using System.Collections.Generic;" as a "using" directive in your source file, or fully-qualify the type name as "System.Collections.IComparer". If you do want to implement System.Collections.Generic.IComparer<T>, then you have to provide a type parameter for the type (i.e. "IComparer<ListViewViewItem>") and then implement that interface. Either way will work fine (though IMHO it is much better to implement the generic interface). But you do need to pick one or the other; it won't work if you have half your code trying to do one, and half your code trying to do the other. :) Pete
From: Zach on 21 Apr 2010 16:53 I added using System.Collections; and the code as I had it worked fine. Zach. "Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> wrote in message news:udBr8ZW4KHA.1660(a)TK2MSFTNGP04.phx.gbl... > Zach wrote: >> 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. > > Just as the error is explaining to you, the use of the > System.Collections.Generic.IComparer<T> type requires one type argument. > You haven't provided one. > > If you want to implement System.Collections.IComparer instead, then either > don't put "using System.Collections.Generic;" as a "using" directive in > your source file, or fully-qualify the type name as > "System.Collections.IComparer". > > If you do want to implement System.Collections.Generic.IComparer<T>, then > you have to provide a type parameter for the type (i.e. > "IComparer<ListViewViewItem>") and then implement that interface. > > Either way will work fine (though IMHO it is much better to implement the > generic interface). But you do need to pick one or the other; it won't > work if you have half your code trying to do one, and half your code > trying to do the other. :) > > Pete
From: Peter Duniho on 21 Apr 2010 21:33 Zach wrote: > I added using System.Collections; and the code as I had it worked fine. Yup, that would yet another way to make sure your class was declared as implementing the interface you really wanted to implement.
|
Next
|
Last
Pages: 1 2 Prev: How to I assign some bytes in hex to a byte array Next: Can't find aximp.exe |