I would like to define Sorted to be of type ErrorProviderMessageCollection, which is what unsortedCollection is defined as.
Dim Sorted As ErrorProviderMessageCollection = From item In unsortedCollection
Order By item.Control.TabIndex
How do I do this?
Public Class ErrorProviderMessage Implements IComparable(Of ErrorProviderMessage)
Private _Message As String
Private _Control As Control
Public Sub New(ByVal message As String, ByVal control As Control)
_Message = message
_Control = control
End Sub
Public ReadOnly Property Message() As String
Get
Return _Message
End Get
End Property
Public ReadOnly Property Control() As Control
Get
Return _Control
End Get
End Property
Public Function CompareTo(ByVal other As ErrorProviderMessage) As Integer Implements System.IComparable(Of ErrorProviderMessage).CompareTo
Return Me.Control.TabIndex.CompareTo(other.Control.TabIndex)
End Function
End Class
Public Class ErrorProviderMessageCollection
Inherits System.Collections.ObjectModel.Collection(Of ErrorProviderMessage)
End Class
You could also use Lambda and an appropriate extension method to deal with the casting e.g:
and the extension method…
I’m not up on VB.NET so provide the code example in C#.