[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Error trying to sort custom class/collection

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
        InitValue
        Available
        ColumnName
        ColumnType
        HeaderText
        Index
        Visible
        Width
    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
            MyBase.Reverse()
        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,
Chris
0
pillbug22
Asked:
pillbug22
1 Solution
 
platinumbayCommented:
Try this:

http://www.ondotnet.com/pub/a/dotnet/2003/06/02/collectionbase.html

About halfway down is how to sort.
0
 
pillbug22Author Commented:
DOH!

(found it)

My .Sort() method needs 2 args and I was only passing one...must...need...sleep...
0
 
CetusMODCommented:
Question PAQ'd
125 points refunded.

CetusMOD
Community Support Moderator
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now