Sort pair values using numeric column

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dot net work

    Sort pair values using numeric column

    I would like to keep track of pairs of values, like this:

    Apple 50
    Pear 100
    Banana 30

    I would like to keep this data sorted using the number column, and not
    the text column.

    So, I need this:

    Pear 100
    Apple 50
    Banana 30

    Please can someone recommend a good .NET framework "structure" that
    would help me achieve this.

    TIA,
    -dnw.
  • Imran Koradia

    #2
    Re: Sort pair values using numeric column

    Take a look athe System.Collecti ons.SortedList class. Add the number as the
    key and the string as the item and you should have your items sorted.

    eg. Dim oSortedList as New SortedList
    oSortedList.Add (50, "Apple")
    oSortedList.Add (100, "Pear"), etc

    hope this helps..
    Imran.

    "Dot net work" <dotnw@hotmail. com> wrote in message
    news:77b8c5a9.0 408270513.1eeae e3a@posting.goo gle.com...[color=blue]
    > I would like to keep track of pairs of values, like this:
    >
    > Apple 50
    > Pear 100
    > Banana 30
    >
    > I would like to keep this data sorted using the number column, and not
    > the text column.
    >
    > So, I need this:
    >
    > Pear 100
    > Apple 50
    > Banana 30
    >
    > Please can someone recommend a good .NET framework "structure" that
    > would help me achieve this.
    >
    > TIA,
    > -dnw.[/color]


    Comment

    • Dot Net Work

      #3
      Re: Sort pair values using numeric column

      Thanks a lot.

      As a finishing touch, I added the following:

      'Make a comparer class that can see if an integer is greater or smaller
      than another integer...

      Private Class IntComparer
      Implements IComparer

      Public Function Compare(ByVal x As Object, ByVal y As Object) As
      Integer Implements System.Collecti ons.IComparer.C ompare
      Dim x1 As Integer
      Dim x2 As Integer

      x1 = Convert.ToInt32 (x)
      x2 = Convert.ToInt32 (y)

      If x1 < x2 Then Return 1 Else Return -1
      End Function
      End Class

      'Next, make a sorted list, and use the above comparer class.

      Dim oSL As New SortedList(New IntComparer())

      'Then, in this particular case, your items are sorted with the highest
      integer at the top (which is what I need)

      So, if you have

      50 Apple
      100 Pear

      Your list is sorted as:

      100 Pear
      50 Apple

      Thanks, dnw.


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...