• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1185
  • Last Modified:

filelistbox > name and date sort

I want to be able to sort a filelistbox (named file1) ascending and descending at name and date.

How can that be achieved ?
0
saskia
Asked:
saskia
  • 2
1 Solution
 
prasitleeCommented:
Dear saskia,
    If you are using ListBox as the control for showing file, try to change the property "Sorted" to TRUE. All files in FileListBox would be sorted as you needed.
                                                      Meng
0
 
mccainz2Commented:
Well , don't think you should use a fileList box for this , I wrote a quickie app using a regular listbox .... code follows
Modify the sort string to get your desired results .

Private Sub Command1_Click()

    If Not LoadFiles("C:\DX9\Lib") Then
        MsgBox "Files failed to load."
    End If
   
End Sub


Private Function LoadFiles(sFolder As String)

    Dim objFSO As New FileSystemObject
    Dim objFile As File
    Dim objFolder As Folder

    Dim dDate As Date
    Dim objRetRS As New ADODB.Recordset
    Dim strFilter As String
   
    LoadFiles = False
   
    objRetRS.CursorLocation = adUseClient
    objRetRS.ActiveConnection = Nothing
   
    'Set up our columns etc....
   
    objRetRS.Fields.Append "FileName", adVarChar, 250
    objRetRS.Fields.Append "FileDate", adDate
   
    objRetRS.Open
   
    If objFSO.FolderExists(sFolder) Then
        Set objFolder = objFSO.GetFolder(sFolder)
    Else
        GoTo err_exit
    End If
   
    For Each objFile In objFolder.Files
        objRetRS.AddNew
            objRetRS.Fields("FileName") = objFile.Name
            objRetRS.Fields("FileDate") = objFile.DateLastModified
        objRetRS.Update
    Next
   
    objRetRS.Sort = "FileDate,FileName"
    objRetRS.MoveFirst
   
    While Not (objRetRS.EOF)
        List1.AddItem objRetRS("FileName")
        objRetRS.MoveNext
    Wend
   
    LoadFiles = True
   
err_exit:
End Function
0
 
mccainz2Commented:
Regarding sybtax for Ascending and descending sorting ...
For example
 objRetRS.Sort = "FileName DESC,FileDate ASC"
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now