Problem compiling new VB.Net class
Hi all,
I have a VB.Net app that uses a ListView object. Since I want to be able to sort the columns of the ListView by clicking on the column headers I decided to write/plunder(!) a class to do this. I hunted around on the net first to get an idea how to do it and found a class (in C#) which I decided to convert.
I've done the conversion from C# to VB.Net but am getting one really stubborn error that I can't solve. The error I'm getting from the class (listed below) is this:
E:\VS.NET\Projects\BatchRename\ListViewSortManager.vb(21): 'BatchRename.MJC.Windows.Forms.ListViewTextSort' must implement 'Overridable Overloads Function Compare(x As Object, y As Object) As Integer' for interface 'System.Collections.IComparer'.
The thing is I *am* implementing Compare in my class - exactly how VS.Net tells me it wants it!
Here's the code...
Public Class ListViewTextSort
Implements IComparer
Private m_column As Integer
Private m_ascending As Boolean
'Constructor
Public Sub New(ByVal column As Integer, ByVal ascending As Boolean)
m_column = column
m_ascending = ascending
End Sub
'Implementation of IComparer.Compare
Overridable Overloads Function Compare(ByVal lhs As Object, ByVal rhs As Object) As Integer
Dim lhsLvi As ListViewItem = CType(lhs, ListViewItem)
Dim rhsLvi As ListViewItem = CType(rhs, ListViewItem)
If lhsLvi Is Nothing Or rhsLvi Is Nothing Then
Return 0
End If
Dim lhsItems As ListViewItem.ListViewSubItemCollection = lhsLvi.SubItems
Dim rhsItems As ListViewItem.ListViewSubItemCollection = rhsLvi.SubItems
Dim lhsText As String
Dim rhsText As String
If lhsItems.Count > m_column Then
lhsText = lhsItems(m_column).Text
Else
lhsText = String.Empty
End If
If rhsItems.Count > m_column Then
rhsText = rhsItems(m_column).Text
Else
rhsText = String.Empty
End If
Dim result As Integer = 0
If lhsText.Length = 0 Or rhsText.Length = 0 Then
result = lhsText.CompareTo(rhsText)
Else
result = OnCompare(lhsText, rhsText)
End If
If Not m_ascending Then
result = -result
End If
Return result
End Function
'Overridden to do type-specific comparision.
Protected Overridable Function OnCompare(ByVal lhs As String, ByVal rhs As String) As Integer
Return String.Compare(lhs, rhs, False)
End Function
End Class
I'm really no OO expert - can anybody spot what the problem might be here?
TIA...
Mike.