hi all,
is there a way to show the icons of a file, used by the system in a
listview.
now i have something like:
Private Sub AddFiles(ByVal nod As TreeNode)
Dim strPath As String = nod.FullPath
Dim strFile As String
With nod
For Each strFile In Directory.GetFi les(strPath)
With nod.Nodes.Add(P ath.GetFileName (strFile))
..Tag = ItemType.File
..ImageIndex = 3
End With
Next
End With
End Sub
kind regards,
Maarten 3 2256
Hi,
Use shgetfileinfo to get them. Here a listview control to the form
and name it lv. Here is an example.
Private Function getLocalIcons(B yVal szFolderPath As String)
Dim dirInfo As New System.IO.Direc toryInfo(szFold erPath)
Dim di As System.IO.Direc toryInfo
Dim fi As System.IO.FileI nfo
Dim lvitem As ListViewItem
Dim hIcon As Icon
Dim cIcon As New clsGetIcon
Dim htIcons As New Hashtable
Dim intIndex As Integer
imlIcon.Images. Clear()
lv.Items.Clear( )
lv.SmallImageLi st = imlIcon
For Each di In dirInfo.GetDire ctories()
lvitem = lv.Items.Add(di .Name)
hIcon = cIcon.getIcon(d i.FullName)
If htIcons.Contain sKey(hIcon) Then
intIndex = htIcons(hIcon)
Else
imlIcon.Images. Add(hIcon.ToBit map)
intIndex = imlIcon.Images. Count - 1
End If
lvitem.ImageInd ex = intIndex
Next
For Each fi In dirInfo.GetFile s()
lvitem = lv.Items.Add(fi .Name)
hIcon = cIcon.getIcon(f i.FullName)
If htIcons.Contain sKey(hIcon) Then
intIndex = htIcons(hIcon)
Else
imlIcon.Images. Add(hIcon.ToBit map)
intIndex = imlIcon.Images. Count - 1
End If
lvitem.ImageInd ex = intIndex
Next
End Function
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
lv.SuspendLayou t()
getLocalIcons(" C:\")
lv.ResumeLayout ()
End Sub
The helper class.
Imports System.Runtime. InteropServices
Public Class clsGetIcon
Public Structure SHFILEINFO
Dim hIcon As IntPtr
Dim iIcon As Integer
Dim dwAttributes As Integer
<VBFixedString( 260),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lTStr,
SizeConst:=260) > Public szDisplayName As String
'String that contains the name of the file as it appears in the Microsoft®
Windows® Shell, or the path and file name of the file that contains the icon
representing the file.
<VBFixedString( 80),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lTStr,
SizeConst:=80)> Public szTypeName As String
End Structure
Private Declare Auto Function SHGetFileInfo Lib "shell32" (ByVal pszPath As
String, _
ByVal dwFileAttribute s As Integer, ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As Integer
Private Const SHGFI_ICON As Integer = &H100
Private Const SHGFI_SMALLICON As Integer = &H1 'Small icon
Private Const SHGFI_TYPENAME As Integer = &H400 ' get type name
Public Function getIcon(ByVal szFilename As String) As Icon
Try
Dim aSHFileInfo As New SHFILEINFO
Dim cbFileInfo As Integer = _
Marshal.SizeOf( aSHFileInfo)
Dim uflags As Integer = SHGFI_ICON Or SHGFI_SMALLICON
SHGetFileInfo(s zFilename, 0, aSHFileInfo, cbFileInfo, uflags)
Dim myIcon As Icon
myIcon = Icon.FromHandle (aSHFileInfo.hI con)
aSHFileInfo.szT ypeName = Space(255)
SHGetFileInfo(s zFilename, 0, aSHFileInfo, cbFileInfo, SHGFI_TYPENAME)
Trace.WriteLine (aSHFileInfo.sz TypeName)
Return myIcon
Catch ex As Exception
Debug.WriteLine (ex.ToString)
Return Nothing
End Try
End Function
End Class
Ken
---------------------------
"Maarten" <gu******@hotma il.com> wrote in message
news:41******** **************@ news.skynet.be. ..
hi all,
is there a way to show the icons of a file, used by the system in a
listview.
now i have something like:
Private Sub AddFiles(ByVal nod As TreeNode)
Dim strPath As String = nod.FullPath
Dim strFile As String
With nod
For Each strFile In Directory.GetFi les(strPath)
With nod.Nodes.Add(P ath.GetFileName (strFile))
..Tag = ItemType.File
..ImageIndex = 3
End With
Next
End With
End Sub
kind regards,
Maarten
"Maarten" <gu******@hotma il.com> schrieb: is there a way to show the icons of a file, used by the system in a listview.
System Image List
<URL:http://vbaccelerator.c om/article.asp?id= 4303>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
thank you it works fine,
regards,
Maarten
"Ken Tucker [MVP]" <vb***@bellsout h.net> schreef in bericht
news:O#******** ******@TK2MSFTN GP11.phx.gbl... Hi,
Use shgetfileinfo to get them. Here a listview control to the
form and name it lv. Here is an example.
Private Function getLocalIcons(B yVal szFolderPath As String)
Dim dirInfo As New System.IO.Direc toryInfo(szFold erPath)
Dim di As System.IO.Direc toryInfo
Dim fi As System.IO.FileI nfo
Dim lvitem As ListViewItem
Dim hIcon As Icon
Dim cIcon As New clsGetIcon
Dim htIcons As New Hashtable
Dim intIndex As Integer
imlIcon.Images. Clear()
lv.Items.Clear( )
lv.SmallImageLi st = imlIcon
For Each di In dirInfo.GetDire ctories()
lvitem = lv.Items.Add(di .Name)
hIcon = cIcon.getIcon(d i.FullName)
If htIcons.Contain sKey(hIcon) Then
intIndex = htIcons(hIcon)
Else
imlIcon.Images. Add(hIcon.ToBit map)
intIndex = imlIcon.Images. Count - 1
End If
lvitem.ImageInd ex = intIndex
Next
For Each fi In dirInfo.GetFile s()
lvitem = lv.Items.Add(fi .Name)
hIcon = cIcon.getIcon(f i.FullName)
If htIcons.Contain sKey(hIcon) Then
intIndex = htIcons(hIcon)
Else
imlIcon.Images. Add(hIcon.ToBit map)
intIndex = imlIcon.Images. Count - 1
End If
lvitem.ImageInd ex = intIndex
Next
End Function
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
lv.SuspendLayou t()
getLocalIcons(" C:\")
lv.ResumeLayout ()
End Sub The helper class.
Imports System.Runtime. InteropServices
Public Class clsGetIcon
Public Structure SHFILEINFO
Dim hIcon As IntPtr
Dim iIcon As Integer
Dim dwAttributes As Integer
<VBFixedString( 260),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm a
nagedType.ByVal TStr, SizeConst:=260) > Public szDisplayName As String
'String that contains the name of the file as it appears in the Microsoft® Windows® Shell, or the path and file name of the file that contains the
icon representing the file.
<VBFixedString( 80),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm a
nagedType.ByVal TStr, SizeConst:=80)> Public szTypeName As String
End Structure
Private Declare Auto Function SHGetFileInfo Lib "shell32" (ByVal pszPath
As String, _
ByVal dwFileAttribute s As Integer, ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As Integer
Private Const SHGFI_ICON As Integer = &H100
Private Const SHGFI_SMALLICON As Integer = &H1 'Small icon
Private Const SHGFI_TYPENAME As Integer = &H400 ' get type name Public Function getIcon(ByVal szFilename As String) As Icon
Try
Dim aSHFileInfo As New SHFILEINFO
Dim cbFileInfo As Integer = _
Marshal.SizeOf( aSHFileInfo)
Dim uflags As Integer = SHGFI_ICON Or SHGFI_SMALLICON
SHGetFileInfo(s zFilename, 0, aSHFileInfo, cbFileInfo, uflags)
Dim myIcon As Icon
myIcon = Icon.FromHandle (aSHFileInfo.hI con)
aSHFileInfo.szT ypeName = Space(255)
SHGetFileInfo(s zFilename, 0, aSHFileInfo, cbFileInfo, SHGFI_TYPENAME)
Trace.WriteLine (aSHFileInfo.sz TypeName)
Return myIcon
Catch ex As Exception
Debug.WriteLine (ex.ToString)
Return Nothing
End Try
End Function
End Class Ken
---------------------------
"Maarten" <gu******@hotma il.com> wrote in message news:41******** **************@ news.skynet.be. .. hi all,
is there a way to show the icons of a file, used by the system in a listview.
now i have something like:
Private Sub AddFiles(ByVal nod As TreeNode)
Dim strPath As String = nod.FullPath
Dim strFile As String
With nod
For Each strFile In Directory.GetFi les(strPath)
With nod.Nodes.Add(P ath.GetFileName (strFile))
.Tag = ItemType.File
.ImageIndex = 3
End With
Next
End With
End Sub kind regards,
Maarten This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: James |
last post by:
I created a .Net add-in for Microsoft Excel.When the application load, all
the images that will be used in the application will be loaded. I have a few
forms, and some of them contain ListView control. I used the LargeIcon view
with 72x40 pixel icons. The listview has about 20 items.
My problem is: Sometime the image is not displayed. The space for the image
is there, but the image is not displayed. The more interesting thing is:
this...
|
by: Silvia |
last post by:
Hi,
I have a program that capture images and put this into a listview (using imagelist), the problem is when I delete de image
the listview, when do that and capture another image, the image painting in the listview is the image delete, I supose
that the problem is that the image exist in the imagelist, in order to solve this problem I clear the imagelist and add all
the images captured, but i have another problem now, some time when I...
|
by: Nak |
last post by:
Hi there,
I've come across quite an annoying bug after optimizing some of my code
(which sounds quite strange I know), but take this for a description of my
problem.
* I have a background thread continually monitoring a collection, when
items are available in the collection they are dealt with.
* The items in question are files for images, when files appear in the
collection the thread makes a thumbnail for it (which is associated...
|
by: Lloyd Sheen |
last post by:
I have now googled for a couple of hours with no success. I am looking to
find code to create a listview with a background image. I know it can be
done but cannot find a link to code or a hint.
Lloyd Sheen
|
by: ±è¿ë°Ç |
last post by:
i tried to set listview's background image
(using managed C++)
first try, i maked bitmap and set back ground image like below code
but, it had no effect
LiveView * listViewJobTable
....
HBITMAP hBitmap =
LoadBitmap(g_hInstance,MAKEINTRESOURCE(IDB_BITMAPJOBLIST));
| |
by: Adam Honek |
last post by:
This is probably a silly question but oh well, I can't find the answer
looking via code.
Having an imagelist already, how does one set an icon for a list view's sub
items?
I'm using the code below however the subitems doesn't have an overload
allowing an image index.
Adam
|
by: mrmagoo |
last post by:
I'm trying to fill a listview with data. I'm using the example from the help
file, but how do I modify this to avoid using images? I want the exact same
layout but without images. This procedure seems so dependent on the image
being the "anchor" of each row that I don't understand how to modify it.
Thanks.
Dim lv As ListView
lv = Me.ListView1
|
by: grzegorz.gazda |
last post by:
Hi all
Is there any limit of images which can be added to a image list. I
have a problem with this control. I added an image list in design mode
and I am adding images using code. Then I want to use images in a
listview, and each time I am trying to call an image at index 15 or
above I have an error stating that there isn't any object at that
index. I was debbuging it and there was more there was 22 images, but
only 15 I can load.
Is...
|
by: Diego F. |
last post by:
Hi all. I have a listview with images and my application must be able to
rotate one image. I need a method to rotate 90 degrees rigth (i.e.).
Is that possible?
--
Regards,
Diego F.
|
by: parshupooja |
last post by:
Contact Reply
1 point Member
propoo
Joined on 08-31-2007, 10:32 PM
Posts 3
Hey all ,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |