Solved

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

Posted on 2013-01-25
5
359 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error running webpage local computer 7 26
asp.net mvc 2 33
asp.net figure out error 3 23
Powershell form - Anchor a button to a dynamically sized groupbox 2 43
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

756 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