DateTime order

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • truezplaya
    New Member
    • Jul 2007
    • 115

    DateTime order

    hey all
    I have a small but very annoying problem.
    I collect two sets of data from two different databases, This data is now in two collections. I then join/append the one collection to the other and then put it in to a list view.
    That part works

    I really would like to order this list view by the first column without the click event.
    To make this even harder the First column contains Data that is DateTime and i have found that it orders the items by the day number and not the months or years or time.

    I have found one way but it then cause's me further agony when doing some checks upon the data within the listview later in my code. This answer is to rearrange the format to "yyyy-MM-dd HH:mm:SS"
    then using the listview.sortin g = sortorder.The order you wish

    Any suggestions would be muchly appreciated

    cheers

    Truez
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    what about " DataTableName.D efaultView.Sort = "DataColumnName " '

    Comment

    • truezplaya
      New Member
      • Jul 2007
      • 115

      #3
      Possibly would work if the data was in a dataTable

      Comment

      • jg007
        Contributor
        • Mar 2008
        • 283

        #4
        sorry, I was not clear how you were getting it from the database to the list box so assumed that you were getting a datatable from an oledb query and then using it as the datasource.

        Comment

        • truezplaya
          New Member
          • Jul 2007
          • 115

          #5
          i do but i get them from two differnet sources then add them both to a collection. I then merge these collections, this is when i would like to do the sort.

          Comment

          • truezplaya
            New Member
            • Jul 2007
            • 115

            #6
            Here is a solution that someone i know came up with.
            temp is a myCollection that has data in it
            Code:
            Dim sortedCollection As New myCollection
            
                    For index As Integer = 0 To (temp.Count - 1)
            
                        Dim highestDate As DateTime = Nothing
                        Dim hightestIndex As Integer = 0
            
                        For subIndex As Integer = 0 To (temp.Count - 1)
            
                            If temp(subIndex).committedToSort = False Then
                                If temp(subIndex).sortDateTime > highestDate Then
                                    hightestIndex = subIndex
                                    highestDate = temp(subIndex).sortDateTime
                                End If
                            End If
            
                        Next
            
                        sortedCollection.Add(temp(hightestIndex))
            
                        temp(hightestIndex).committedToSort = True
            
                    Next

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Why not join them into a DataTable and then sort it, and then use that as a datasource?

              Comment

              • truezplaya
                New Member
                • Jul 2007
                • 115

                #8
                I was editing someone else's code and they have done everything in collections and i thought i would do it the way you suggested but to add to the difficulty of the situation the data was coming from two different databases so the dates were different formats, one a timestamp and one dateTime i believe. To keep the flow of the code i thought since it's been put in to a collection i will keep it in this format as i am not totally familliar with the concept of the programming that has been use. This is when i got some help and they came up with that little bad boy!

                Comment

                Working...