troubleshooting Question


Avatar of pcavacas
pcavacas asked on
.NET Programming
4 Comments1 Solution849 ViewsLast Modified:
I have a class that inherits from collection base and I want to implement a custom comparing mechanism with the sort routine.

So in my collection I want to have something like

Sort(columnIndex as int32, sortOrder as ComponentModel.ListSortOrder)

Now I know that I can create a class that implements an IComparer interface and pass this class into the Sort method of the InnerList property of the CollectionBase class and have tried this, but it is not ever calling my comparing code.

Here is what I have:

Public Class NodeCollection
Inherits CollectionBase

        Public Sub Sort(ByVal columnIndex As Int32, ByVal sortOrder As System.ComponentModel.ListSortDirection)
            Dim sorter As New Node.AdvancedSort
            sorter.ColumnIndex = columnIndex
            sorter.ListSortOrder = sortOrder
        End Sub

End Class

Public Class Node

    Public Class AdvancedSort
            Implements System.Collections.IComparer

            Private _ColumnIndex As Int32
            Private _ListSortOrder As System.ComponentModel.ListSortDirection

            Public Property ColumnIndex() As Int32
                    Return _ColumnIndex
                End Get
                Set(ByVal Value As Int32)
                    _ColumnIndex = Value
                End Set
            End Property

            Public Property ListSortOrder() As System.ComponentModel.ListSortDirection
                    Return _ListSortOrder
                End Get
                Set(ByVal Value As System.ComponentModel.ListSortDirection)
                    _ListSortOrder = Value
                End Set
            End Property

            Public Function Compare(ByVal x As Object, ByVal y As Object) As Int32 Implements System.Collections.IComparer.Compare
               'My logic to sort is here
            End Sub
   End Class
End Class

Nowif I step through the code in the Sort method and put a breakpoint or any code (like throwing an exception) in the Compare method that code is never executed and my collection is not being sorted
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros