Solved

Dim collection As New Dictionary(Of String, String) - ORDER BY

Posted on 2013-01-25
5
369 Views
Last Modified: 2013-01-30
In the folowing code i want to order what is in the collection by SalesAmountDescr

How would i do so?


 For Each SalesAmountRow In TransSale.IPrimarySale.ISalesAmountList
         
                Dim collection As New Dictionary(Of String, String)
                collection.Add("SalesAmountDescr", SalesAmountRow.SalesAmountDescr.ToString())
                collection.Add("SalAmount", SalesAmountRow.TermPrem.ToString())
                collection.Add("SalesAmountType", SalesAmountRow.SalesAmountType.ToString())
         
       
        Next
0
Comment
Question by:vbnetcoder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 38820614
You should use  Sorted dictionary.
Please clarify for me if you need to sort by SalesAmountDescr contents in order to get the associated amount and amout type.
If so you need to create an extra class called SalesAmount that contains 3 properties:
SalesAmountDescr, SalAmount and SalesAmountType.
Then your collection code sample should change to:
Dim collection As New Dictionary(Of String, SalesAmount)
Dim key As String = SalesAmountRow.SalesAmountDescr.ToString
Dim entry As New SalesAmount()
//fill entry props.
 collection.Add(key, entry)
0
 

Author Comment

by:vbnetcoder
ID: 38820678
I just need to list the amounts by the SalesAmountDescr
0
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 38820784
In this case:
Dim collection As New SortedDictionary(Of String, String)
For Each SalesAmountRow In TransSale.IPrimarySale.ISalesAmountList
     collection.Add( SalesAmountRow.SalesAmountDescr.ToString(),SalesAmountRow.TermPrem.ToString())       
Next 

Open in new window

The order is ascendent order by SalesAmountDescr, if you require a different sort order implement the collection.Comparer property.
0
 
LVL 28

Accepted Solution

by:
Ark earned 500 total points
ID: 38821658
Or use LINQ if ISalesAmountList supports IEnumerable:
For Each SalesAmountRow In TransSale.IPrimarySale.ISalesAmountList.OrderBy(Function(p) p.SalesAmountDescr)

Open in new window

0
 

Author Closing Comment

by:vbnetcoder
ID: 38835837
ty this is what worked for me
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question