Sorting a collection of collections?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sdunkerson@data-tronics.com

    #1

    Sorting a collection of collections?

    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.Collecti ons.DictionaryB ase

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

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

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

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

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

    Public Function DictionaryHasht able() As Hashtable
    Return Me.InnerHashtab le
    End Function

    End Class


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


    <Serializable() > _
    Public Class RptItems
    Inherits System.Collecti ons.DictionaryB ase

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

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

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

    Public Sub Remove(ByVal key As String)
    Me.Dictionary.R emove(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

  • tommaso.gastaldi@uniroma1.it

    #2
    Re: Sorting a collection of collections?

    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[color=blue]
    > dictionaty collection of Object "B". Can I sort Object "A" using one of
    > the properties within the collection of Objects "B"?[/color]

    Comment

    Working...