[RESOLVED] Listview slowness
So I have this app that has a treeview and listview on it. Basically a mini explorer window without any bells or whistles. All it does is shows icons that are shortcuts loaded from the local C drive. Been working for years just fine. I have noticed that recently the listview part is slow on folders that have a lot of icons to show. I say a lot of icons but at most it could be 170. Not a lot. If I click on a folder that has very few icons, say 10, and leave it there for a few hours, then click on the folder that has 150 icons, it almost acts like the app is crashing. It states Not Responding and then a few seconds later, more like 10secs, it finally comes up and looks fine. Curious if a .NET update has changed something? Only acts slow when you don't use it for a few hours. Once you do use it and go back and forth, it's pretty fast. Thoughts??? Anybody else experience something like this?
Here is the sub that loads the icons in the listview
Code:
Public Sub ListFoldersFiles(ByVal apath As String, ByVal lvTemp As ListView, ByVal imgLtemp As ImageList)
' Create a reference to the current directory.
Dim di As New DirectoryInfo(apath)
' 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()
'lvTemp.Sorting = SortOrder.Ascending
'i = 0
'MsgBox(fi.Length)
' Loop through each file in the directory
lvTemp.BeginUpdate()
For Each fiTemp In fi
Dim strImageKey As String = String.Empty
Try
' gets the icon from file
Dim ico As Icon = Icon.ExtractAssociatedIcon(apath & fiTemp.Name)
If ico IsNot Nothing Then
Dim bmp As Bitmap = ico.ToBitmap()
strImageKey = bmp.GetHashCode.ToString
imgLtemp.Images.Add(strImageKey, bmp)
Form1.ImageList3.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))
Dim fname As String = 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.
m_Shortcut = New ShellShortcut(apath & fiTemp.Name)
Dim item As New ListViewItem(fname, imgLtemp.Images.Count - 1) With {.Tag = apath & fiTemp.Name, .ToolTipText = m_Shortcut.Description}
lvTemp.Items.Add(item)
' used in details view
If Form1.tvFolders.SelectedNode.Name <> "Home" Then
item.SubItems.Add(Form1.tvFolders.SelectedNode.Parent.Name)
item.SubItems.Add(m_Shortcut.Description) ' adds the tooltip text to the description column
Else
item.SubItems.Add("Home")
item.SubItems.Add(m_Shortcut.Description) ' adds the tooltip text to the description column
End If
item.SubItems.Add(fname.ToString)
Next fiTemp
lvTemp.EndUpdate()
End If
End Sub