Reputation: 75
I have a code issue in vb.NET that I have not been able to resolve for several days. Please be indulgent, I am not fluent in English, I am French! So my first piece of code fills the 3 columns of my listview while the second code extracts the icons from the files. But I can't match the two, I think my first code is incomplete! First code:
For Each file In FileIO.FileSystem.GetFiles(Path)
Dim item As ListViewItem = ListView1.Items.Add(FileIO.FileSystem.GetName(file))
item.SubItems.Add(FileIO.FileSystem.GetFileInfo(file).Length & " octets")
item.SubItems.Add(FileIO.FileSystem.GetFileInfo(file).CreationTime)
Next
Second code:
Private Sub ExtractAssociatedIconEx()
ListView1.LargeImageList = ImageList1
ListView1.SmallImageList = ImageList1
Dim dirInfo As IO.DirectoryInfo
Dim fileInfo As IO.FileInfo
Dim exeIcon As System.Drawing.Icon
dirInfo = New IO.DirectoryInfo(StrShortPath & "\Librairies\")
For Each fileInfo In dirInfo.GetFiles
If Not String.IsNullOrEmpty(fileInfo.Extension) Then
exeIcon = System.Drawing.Icon.ExtractAssociatedIcon(fileInfo.FullName)
If ImageList1.Images.ContainsKey(fileInfo.FullName) Then
ListView1.Items.Add(fileInfo.Name, fileInfo.FullName)
ElseIf Not exeIcon Is Nothing Then
ImageList1.Images.Add(fileInfo.FullName, exeIcon)
ListView1.Items.Add(fileInfo.Name, fileInfo.FullName)
Else
ListView1.Items.Add(fileInfo.Name)
End If
End If
Next
End Sub
I can't seem to link the two, and if the two work separately, they don't work together. Thanks in advance. If you have another solution, I am obviously interested. Regards,
Claude
PS: the second code comes from Stack Overflow, a little over six months, I came to find it. Thanks to its author.
Upvotes: 2
Views: 211