I have this function that gets the files in a specific folder to be added to the listview. That all works, but I am looking to sort the files before they are added to the listview. The problem is if I sort the listview in properties and then add the files to the list, the listview item tags are not set, they are as how they get added to the listview.
I have search and found LINQ but when I try it sorts are different than the lsitview property sort
Code:Public Function ListFoldersFiles(ByVal path As String, ByVal lvTemp As ListView, ByVal imgLtemp As ImageList) As String() ' Create a reference to the current directory. Dim di As New DirectoryInfo(path) 'MsgBox(di.ToString) If Directory.Exists(di.ToString) Then ' Create an array representing the files in the current directory. Dim fi As FileInfo() = di.GetFiles() Dim fiTemp As FileInfo Dim i As Short Array.Sort(fi, New compclass(SortOrder.Ascending)) lvTemp.Items.Clear() i = 0 ' Loop through each file in the directory For Each fiTemp In fi Dim strImageKey As String = String.Empty Try ' gets the icon from file Dim ico As Icon = Icon.ExtractAssociatedIcon(path & fiTemp.Name) If ico IsNot Nothing Then Dim bmp As Bitmap = ico.ToBitmap() strImageKey = bmp.GetHashCode.ToString imgLtemp.Images.Add(strImageKey, bmp) End If Catch ex As Exception End Try ' split the extension off so we can use just the text. Dim rFileName As Array = Split(fiTemp.Name, ".") ' MsgBox(rFileName(0)) lvTemp.Items.Add(fiTemp.Name, rFileName(0), strImageKey) ' add full name to tag so we can call it later seeing how we ' don't use the extension for the text. lvTemp.Items(i).Tag = path & fiTemp.Name ' MsgBox(lvTemp.Items(i).Tag) i = i + 1 Next fiTemp End If End Function




Reply With Quote