Error trying to sort custom class/collection

Posted on 2004-11-22
Last Modified: 2010-04-24
Hi everyone...

I have a class and collection in a current project (highly modfied version of MS's TaskVision), and am trying to sort the collection, but get the error:

Value of type 'TaskVision.ColumnRegistryKeyCollection.ColumnRegistryKeyFields' cannot be converted to 'System.Collections.IComparer'.

Here my calling code:
        Dim column As New ColumnRegistryKey()
        Dim Columns As New ColumnRegistryKeyCollection()
        Columns = ColumnRegistryKey.Load()
        Columns.Sort(ColumnRegistryKeyCollection.ColumnRegistryKeyFields.Index)          ' <-- Error here

Here's the basics of the ColumnRegistryClass:

Public Class ColumnRegistryKey
    Private _Available As Boolean
    Private _ColumnName As String = String.Empty
    Private _ColumnType As String = String.Empty
    Private _HeaderText As String = String.Empty
    Private _Index As Integer
    Private _Visible As Boolean
    Private _Width As Integer

' (plus all Subs and Properties for given variables)


And the basics of the collection class:

Imports System
Imports System.Collections

Public Class ColumnRegistryKeyCollection
    Inherits ArrayList

    Public Enum ColumnRegistryKeyFields
    End Enum 'ColumnRegistryKeyFields

    Public Overloads Sub Sort(ByVal sortField As ColumnRegistryKeyFields, ByVal isAscending As Boolean)
        Select Case sortField
            Case ColumnRegistryKeyFields.Available
                MyBase.Sort(New AvailableComparer())
            Case ColumnRegistryKeyFields.ColumnName
                MyBase.Sort(New ColumnNameComparer())
            Case ColumnRegistryKeyFields.ColumnType
                MyBase.Sort(New ColumnTypeComparer())
            Case ColumnRegistryKeyFields.HeaderText
                MyBase.Sort(New HeaderTextComparer())
            Case ColumnRegistryKeyFields.Index
                MyBase.Sort(New IndexComparer())
            Case ColumnRegistryKeyFields.Visible
                MyBase.Sort(New VisibleComparer())
            Case ColumnRegistryKeyFields.Width
                MyBase.Sort(New WidthComparer())
        End Select
        If Not isAscending Then
        End If
    End Sub 'Sort

    Private NotInheritable Class AvailableComparer
        Implements IComparer 'ToDo: Add Implements Clauses for implementation methods of these interface(s)

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
            Dim first As ColumnRegistryKey = CType(x, ColumnRegistryKey)
            Dim second As ColumnRegistryKey = CType(y, ColumnRegistryKey)
            Return first.Available.CompareTo(second.Available)
        End Function 'Compare
    End Class 'AvailableComparer

' (and continued for remaining sortable items)


I've used this same code structure for the class and collection (except for replacing the names/variables) before without any issues ntil now, so I'm sure I'm forgetting something fairly simple...

Any thoughts?

Thanks in advance,
Question by:pillbug22
    LVL 6

    Expert Comment

    Try this:

    About halfway down is how to sort.
    LVL 6

    Author Comment


    (found it)

    My .Sort() method needs 2 args and I was only passing one...must...need...sleep...

    Accepted Solution

    Question PAQ'd
    125 points refunded.

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    I'm currently working for a company where I have to upgrade over 50 VB6 programs to VB.NET 2008.  So far I'm about half way through, and I've learned quite a few tricks that drastically improve the performance of VB.NET apps. Because there are a…
    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now