Solved

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

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I need help finding an unknown string value within a string in my VB.Net application 3 37
Tool Box 2 31
Error in query expression 3 30
Replace &lt; with < 14 53
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

948 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

24 Experts available now in Live!

Get 1:1 Help Now