Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 404387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:18:13+00:00 2026-05-12T17:18:13+00:00

I have a two-column ListView linked to a Datapager. The ListView lists all files

  • 0

I have a two-column ListView linked to a Datapager. The ListView lists all files of a particular type in a particular directory, so the data source is an ArrayList of type FileInfo. Consequently, I had to create a Comparer class to use in the ArrayList.Sort method.

FileInfoComparer.vb:

Imports System.IO

Friend Class FileInfoDateComparer
 Implements IComparer

 Public Overridable Overloads Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
  Dim oX As FileInfo = CType(x, FileInfo)
  Dim oY As FileInfo = CType(y, FileInfo)
  Return oX.LastWriteTime.CompareTo(oY.LastWriteTime)
 End Function
End Class

Friend Class FileInfoNameComparer
 Implements IComparer

 Public Overridable Overloads Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
  Dim oX As FileInfo = CType(x, FileInfo)
  Dim oY As FileInfo = CType(y, FileInfo)
  Return oX.Name.CompareTo(oY.Name)
 End Function
End Class

GenerateSortedArray sub:

 Private Sub GenerateSortedArray(ByVal SortColumn As String, ByVal SortDirection As String)
  Dim dirInfo As New DirectoryInfo(Server.MapPath(AppSettings.Item("ContentDir")))
  Dim FileArrayList As New ArrayList(dirInfo.GetFiles("*.msg", SearchOption.TopDirectoryOnly))

  With FileArrayList
   .TrimToSize()
   Select Case SortColumn
    Case "Name"
     .Sort(New FileInfoNameComparer)
    Case Else
     .Sort(New FileInfoDateComparer)
   End Select
  End With

ListView_Sorting:

  Session("SortColumn") = e.SortExpression
  Session("SortDirection") = e.SortDirection

  Call GenerateSortedArray(e.SortExpression, DBNull.Value.ToString)

All this works well, however, I don’t know how to reverse the sort. As you can see from the code, I’ve determined the Sort Direction, but I don’t know how to use it to reverse the sort.

Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:18:13+00:00Added an answer on May 12, 2026 at 5:18 pm

    I have usually done something like this:

    Friend Class FileInfoDateComparer
     Implements IComparer
    
        Private _sortOrder As System.Windows.Forms.SortOrder
    
        Public Sub New(ByVal sortOrder As System.Windows.Forms.SortOrder)
            _sortOrder = sortOrder
        End Sub
    
        Public Overridable Overloads Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
           Dim oX As FileInfo = CType(x, FileInfo)
           Dim oY As FileInfo = CType(y, FileInfo)
           Dim result As Integer = oX.LastWriteTime.CompareTo(oY.LastWriteTime)
           If _sortOrder = System.Windows.Forms.SortOrder.Descending Then
               ' we want the reverse sort order, so we "reverse" the result '
               result = result * -1
           End If
           Return result
     End Function
    End Class
    

    If you don’t want to use the System.Windows.Forms.SortOrder, you can roll your own SortOrder enum. I usually prefer enums over booleans since you will get a clear statement in your code what the value means. Compare these two:

    Dim comparer As New FileInfoDateComparer(True)
    Dim comparer As New FileInfoDateComparer(SortOrder.Descending)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple chart with two column series containing all months in the
I have a listview with two columns and I'm using a context menu to
I have two tables one has a three column composite key. The other needs
Hi I want to have two tables each have an INT id column which
Say I have an MSSQL table with two columns: an int ID column that's
Here's my dilemma - I have a two-column list of elements (styled <div> s)
I have two columns in Excel, like this: A B 0.5 0.4 0.6 0.59
I have the following two columns: SELECT b.ip_address AS IP ,b.mask AS MASK FROM
I have two tables with the same columns, and I need to copy one
I have two tables with the following columns: table1: id, agent_name, ticket_id, category, date_logged

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.