Sorting a collection of collections?

S

sdunkerson

I think this will be a good one for anyone who fancies themselves a wiz
with manipulating data structure in vb.net. Imagine a Dictionary
collection of Object "A". One of the properties of Object "A" is
dictionaty collection of Object "B". Can I sort Object "A" using one of
the properties within the collection of Objects "B"?

Using the data structure below, a report has many lines, each line has
many items, each item is made up of a current value and previous value.
I want to sort the lines of the report using the current value of one
of the items.

Does this make any sense? Can it be done. I know there are people out
there who live to figure out stuff like this (bless you... we need more
of you).

Thanks... Sherry

<Serializable()> _
Public Class RptLines
Inherits System.Collections.DictionaryBase

Public Property Item(ByVal key As String) As RptLine
Get
Return DirectCast(Me.Dictionary.Item(key), RptLine)
End Get
Set(ByVal Value As RptLine)
Me.Dictionary.Item(key) = Value
End Set
End Property

Public Sub Add(ByVal key As String, ByVal value As RptLine)
Me.Dictionary.Add(key, value)
End Sub

Public Function Contains(ByVal key As String) As Boolean
Return Me.Dictionary.Contains(key)
End Function

Public Sub Remove(ByVal key As String)
Me.Dictionary.Remove(key)
End Sub

Public Function Keys() As Collection
Return Me.Keys
End Function

Public Function DictionaryHashtable() As Hashtable
Return Me.InnerHashtable
End Function

End Class


<Serializable()> _
Public Class RptLine
Public Metrics() As RptItems
Public Scope() As String
End Class


<Serializable()> _
Public Class RptItems
Inherits System.Collections.DictionaryBase

Default Public Property Item(ByVal key As String) As RptItem
Get
Return DirectCast(Me.Dictionary.Item(key), RptItem)
End Get
Set(ByVal Value As RptItem)
Me.Dictionary.Item(key) = Value
End Set
End Property

Public Sub Add(ByVal key As String, ByVal value As RptItem)
Me.Dictionary.Add(key, value)
End Sub

Public Function Contains(ByVal key As String) As Boolean
Return Me.Dictionary.Contains(key)
End Function

Public Sub Remove(ByVal key As String)
Me.Dictionary.Remove(key)
End Sub

Public Function Keys() As Collection
Return Me.Keys
End Function
End Class


<Serializable()> _
Public Class RptItem
Public Title() As String
Public CurValue() As Single
Public PrevValue() As Single
End Class
 
T

tommaso.gastaldi

Hi,

I am not sure I have fully understood the problem...

At first sight, it would seem natural to define A as a SortedList
(where items are dictionary entries) and define a Comparer
which uses the properties of objects B which you wish to
use for ranking purposes...

-tom

One of the properties of Object "A" is
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top