T
Ty
I am using the following code to add the system associated icons to a
listview and seem to be having trouble.
When the project is run it seems like there should be an icon as the
text is moved to the right enough for where the icon would be, but
there is no icon showing.
I'm not sure if this is a Vista issue of a listview setup problem. I
am also getting an error when there is no icon associated with an
item.
CODE to get the icons.
Private Sub AddImages(ByVal strFileName As String)
Dim shInfo As SHFILEINFO
shInfo = New SHFILEINFO()
shInfo.szDisplayName = New String(vbNullChar, MAX_PATH)
shInfo.szTypeName = New String(vbNullChar, 80)
Dim hIcon As IntPtr
hIcon = SHGetFileInfo(strFileName, 0, shInfo, Marshal.SizeOf
(shInfo), SHGFI_ICON Or SHGFI_SMALLICON)
Dim MyIcon As System.Drawing.Icon
MyIcon = System.Drawing.Icon.FromHandle(shInfo.hIcon)
ImageList1.Images.Add(strFileName.ToString(), MyIcon)
End Sub
CALLING PROCDURE
Private Sub GetFiles(ByVal sender As Object, ByVal e As
DirectorySelectedEventArgs) Handles dtEvent.DirectorySelected
Dim fName As String 'The file name to get the icon from.
Dim FileExtension As String
Dim SubItemIndex As Integer
Dim DateMod As String
Dim strFileName As String
ListView1.Clear()
fName = e.DirectoryName
'Set up the ListView
ListView1.Columns.Add("File Name", 300,
HorizontalAlignment.Left)
ListView1.Columns.Add("File Type", 80,
HorizontalAlignment.Left)
ListView1.Columns.Add("Date Modified", 150,
HorizontalAlignment.Left)
For Each file As String In IO.Directory.GetFiles(fName)
strFileName = file.Substring(file.LastIndexOf("\"c) + 1)
ListView1.Items.Add(strFileName)
FileExtension = IO.Path.GetExtension(file)
DateMod = IO.File.GetLastWriteTime(file).ToString()
AddImages(file)
ListView1.Items(SubItemIndex).SubItems.Add
(FileExtension.ToString() & " File")
ListView1.Items(SubItemIndex).SubItems.Add(DateMod.ToString
())
SubItemIndex += 1
Next
End Sub
listview and seem to be having trouble.
When the project is run it seems like there should be an icon as the
text is moved to the right enough for where the icon would be, but
there is no icon showing.
I'm not sure if this is a Vista issue of a listview setup problem. I
am also getting an error when there is no icon associated with an
item.
CODE to get the icons.
Private Sub AddImages(ByVal strFileName As String)
Dim shInfo As SHFILEINFO
shInfo = New SHFILEINFO()
shInfo.szDisplayName = New String(vbNullChar, MAX_PATH)
shInfo.szTypeName = New String(vbNullChar, 80)
Dim hIcon As IntPtr
hIcon = SHGetFileInfo(strFileName, 0, shInfo, Marshal.SizeOf
(shInfo), SHGFI_ICON Or SHGFI_SMALLICON)
Dim MyIcon As System.Drawing.Icon
MyIcon = System.Drawing.Icon.FromHandle(shInfo.hIcon)
ImageList1.Images.Add(strFileName.ToString(), MyIcon)
End Sub
CALLING PROCDURE
Private Sub GetFiles(ByVal sender As Object, ByVal e As
DirectorySelectedEventArgs) Handles dtEvent.DirectorySelected
Dim fName As String 'The file name to get the icon from.
Dim FileExtension As String
Dim SubItemIndex As Integer
Dim DateMod As String
Dim strFileName As String
ListView1.Clear()
fName = e.DirectoryName
'Set up the ListView
ListView1.Columns.Add("File Name", 300,
HorizontalAlignment.Left)
ListView1.Columns.Add("File Type", 80,
HorizontalAlignment.Left)
ListView1.Columns.Add("Date Modified", 150,
HorizontalAlignment.Left)
For Each file As String In IO.Directory.GetFiles(fName)
strFileName = file.Substring(file.LastIndexOf("\"c) + 1)
ListView1.Items.Add(strFileName)
FileExtension = IO.Path.GetExtension(file)
DateMod = IO.File.GetLastWriteTime(file).ToString()
AddImages(file)
ListView1.Items(SubItemIndex).SubItems.Add
(FileExtension.ToString() & " File")
ListView1.Items(SubItemIndex).SubItems.Add(DateMod.ToString
())
SubItemIndex += 1
Next
End Sub