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
Solved

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

Posted on 2013-01-25
5
357 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
  • 2
  • 2
5 Comments
 
LVL 35

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 35

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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