Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Sort a collection class?

Sort a collection class?

Scheduled Pinned Locked Moved Visual Basic
helpdatabasealgorithmsquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DA_Loring
    wrote on last edited by
    #1

    Does anyone have any idea how I can go about sorting a collection class. The elements of the class are: Public PointData As Double Public RateData As Double Public TimeData As Double The requirement is to sort on one of the following: PointData (asc) + RateData (Desc) or PointData (Desc) Any help would be very much appreciated!! :zzz: The code of the class collection is: Public Class CPRTData Public PointData As Double Public RateData As Double Public TimeData As Double ' Private data for the write-once ID property. Private mstrID As String ' The first time the ID property is set, the static ' Boolean is also set. Subsequent calls return !ERROR! in the ID. Public Property ID() As String Get ID = mstrID End Get Set(ByVal Value As String) Static blnAlreadySet As Boolean If Not blnAlreadySet Then blnAlreadySet = True mstrID = Value Else mstrID = "!ERROR!" End If End Set End Property End Class Public Class CPRTDataItems Implements System.Collections.IEnumerable 'local variable to hold collection Private mCol As Collection Public Function Add() As String 'create a new object Dim objNewMember As CPRTData Dim sKey As String = "" sKey = "R" & Format(mCol.Count + 1, "0000") objNewMember = New CPRTData objNewMember.ID = sKey 'set the properties passed into the method mCol.Add(objNewMember, sKey) 'return the object created Add = objNewMember.ID objNewMember = Nothing End Function Public Function GetEnumerator() As System.Collections.IEnumerator _ Implements System.Collections.IEnumerable.GetEnumerator GetEnumerator = mCol.GetEnumerator End Function Public Sub Clear() Dim iLoopVar As Integer For iLoopVar = mCol.Count To 1 Step -1 Remove(iLoopVar) Next End Sub Public Function Count() As Integer Count = mCol.Count() End Function Default Public ReadOnly Property Item(ByVal Index As Object) As CPRTData Get Item = mCol.Item(Index) End Get End Property Public Sub Remove(ByRef vntIndexKey As Object) 'used when removing an element from the collection 'vntIndexKey contains either the Index or Key, which is

    K 1 Reply Last reply
    0
    • D DA_Loring

      Does anyone have any idea how I can go about sorting a collection class. The elements of the class are: Public PointData As Double Public RateData As Double Public TimeData As Double The requirement is to sort on one of the following: PointData (asc) + RateData (Desc) or PointData (Desc) Any help would be very much appreciated!! :zzz: The code of the class collection is: Public Class CPRTData Public PointData As Double Public RateData As Double Public TimeData As Double ' Private data for the write-once ID property. Private mstrID As String ' The first time the ID property is set, the static ' Boolean is also set. Subsequent calls return !ERROR! in the ID. Public Property ID() As String Get ID = mstrID End Get Set(ByVal Value As String) Static blnAlreadySet As Boolean If Not blnAlreadySet Then blnAlreadySet = True mstrID = Value Else mstrID = "!ERROR!" End If End Set End Property End Class Public Class CPRTDataItems Implements System.Collections.IEnumerable 'local variable to hold collection Private mCol As Collection Public Function Add() As String 'create a new object Dim objNewMember As CPRTData Dim sKey As String = "" sKey = "R" & Format(mCol.Count + 1, "0000") objNewMember = New CPRTData objNewMember.ID = sKey 'set the properties passed into the method mCol.Add(objNewMember, sKey) 'return the object created Add = objNewMember.ID objNewMember = Nothing End Function Public Function GetEnumerator() As System.Collections.IEnumerator _ Implements System.Collections.IEnumerable.GetEnumerator GetEnumerator = mCol.GetEnumerator End Function Public Sub Clear() Dim iLoopVar As Integer For iLoopVar = mCol.Count To 1 Step -1 Remove(iLoopVar) Next End Sub Public Function Count() As Integer Count = mCol.Count() End Function Default Public ReadOnly Property Item(ByVal Index As Object) As CPRTData Get Item = mCol.Item(Index) End Get End Property Public Sub Remove(ByRef vntIndexKey As Object) 'used when removing an element from the collection 'vntIndexKey contains either the Index or Key, which is

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      You should use a comparer to do sorting of collections. I have an article where I am using generic collections and doing sorting. I use comparers there. Here is the article link: http://www.codeproject.com/useritems/GridViewObjectDataSource.asp[^] Hope that helps. Ben

      D 1 Reply Last reply
      0
      • K kubben

        You should use a comparer to do sorting of collections. I have an article where I am using generic collections and doing sorting. I use comparers there. Here is the article link: http://www.codeproject.com/useritems/GridViewObjectDataSource.asp[^] Hope that helps. Ben

        D Offline
        D Offline
        DA_Loring
        wrote on last edited by
        #3

        I will have a read. Thanks Ben

        David Loring !! Keep Music Live !!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups