Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / May 2006

Tip: Looking for answers? Try searching our database.

Sorting a collection of collections?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sdunkerson@data-tronics.com - 19 May 2006 21:46 GMT
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
tommaso.gastaldi@uniroma1.it - 20 May 2006 00:05 GMT
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
> dictionaty collection of Object "B". Can I sort Object "A" using one of
> the properties within the collection of Objects "B"?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.