473,383 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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.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

May 19 '06 #1
1 1607
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"?


May 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Scott | last post by:
I have a collection where the items in the collection are dates. I want to iterate over the collection and build a value list string for the rowsource of a listbox. The dates in the collection are...
2
by: awiklund | last post by:
Hi, I am sorting an arrayList using a custom comparer, but it sort the element in a uncommon fashion. Take a look at this code. using System; namespace ConsoleApplication8
7
by: Daniel | last post by:
does C# have any collection objects that support sort functionality so that I dont have to write my own sorting algorithm?
6
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.