Solved

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

Posted on 2013-01-25
5
338 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
Comment Utility
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
Comment Utility
I just need to list the amounts by the SalesAmountDescr
0
 
LVL 35

Expert Comment

by:Miguel Oz
Comment Utility
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 27

Accepted Solution

by:
Ark earned 500 total points
Comment Utility
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
Comment Utility
ty this is what worked for me
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now