Link to home
Create AccountLog in
Avatar of indy500fan
indy500fan

asked on

I need to Sort in decending order in a SortedDictionary list? Can I, and if not, what do I use instead?

Friends,

I am using a SortedDictionary, but it is sorting the key opposite of what I want.  I want to sort in Descending order.  Is it possible?  If so, how do I do it.  If not is there an alternative?

I suppose that I could take my value that I am using in the key and before inserting it subtract it from 0 to get a negative number.  The greater the negative number, the higher on the sort list it would be.  Then, when I get it out of the collection, I make it an absolute value and I should then be getting them in the right order, right?  Seems like a weird way of doing it.

Attached you will find all my code associated with it:

Best Regards,
Eric
Dim EntrantList As New SortedDictionary(Of Integer, String)
 
    Private Sub AddCurrentPointsToHistorical()
...
        Try
           EntrantList.Clear()
                        Dim CarNumber As String = Row.CarNumber
                            PointsToStore = HistoricalPoints + CurrentPoints + ThisPolePoints + ThisLapsLedPoints
 
                            SyncLock EntrantList
                                Try
                                    EntrantList.Add(PointsToStore, CarNumber) 'part of added clause
                                Catch ex As Exception
                                End Try
                            End SyncLock
...
End Sub
 
Private Sub DisplayEntrantData()
 ...        
For Each kvp As KeyValuePair(Of Integer, String) In EntrantList
            ThisPointValue = kvp.Key
            Dim CarNumber As String = kvp.Value
            Dim strPointDiff As String = ""
            Dim PointDiff As Integer = 0
            If i = 0 Then
                strPointDiff = "--"
            Else
                PointDiff = LastPointValue - ThisPointValue
                strPointDiff = CType(PointDiff, String)
            End If
          ...        
Next
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of indy500fan
indy500fan

ASKER

It has been a long time.  Good to hear from you too!   Will try tomorrow when I get back in the office .

Thanks for the advice!
Not a problem, talk to you tomorrow.
Wow, hadn't considered a method like this!  

Thank you and sorry for the delay!
Glad that it worked out for you. Have a great day.  ;=)