Listview imagenlist icons

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
13 posts Page 1 of 2
Contributors
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Listview imagenlist icons
AnoPem
Hello im creating a file shredder and i need to know how i can add the associated icons to the files that are shown in the listview, ive been searching for hours and not really found anything that worked as it should

Would be nice if anyone could help me out here
Last edited by AnoPem on Sat Feb 11, 2012 9:19 pm, edited 1 time in total.
https://t.me/pump_upp
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: Listview imagenlist icons
Dummy1912
something like this:
make a new imagelist
add a image into it
then select your listview and go to the properties and select smallimagelist
and select the imagelist
Code: Select all
Dim li As New ListViewItem()
li.SubItems.Add(fi.Name)
li.ImageIndex = 0
Listview1.Items.Add(li)
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Listview imagenlist icons
MrAksel
Something like this?
You do not have the required permissions to view the files attached to this post.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Listview imagenlist icons
AnoPem
Dummy1912 wrote:
something like this:
make a new imagelist
add a image into it
then select your listview and go to the properties and select smallimagelist
and select the imagelist
Code: Select all
Dim li As New ListViewItem()
li.SubItems.Add(fi.Name)
li.ImageIndex = 0
Listview1.Items.Add(li)
I want it to find the associated icons for like exe, txt etc.
by itself
https://t.me/pump_upp
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Listview imagenlist icons
AnoPem
MrAksel wrote:
Something like this?
it excatly like that but i dont know how i can get it without the treeview
https://t.me/pump_upp
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Listview imagenlist icons
MrAksel
Do you see the file Icons.vb? You can use that class to get the icon from a file.
Code: Select all
Dim Icons As New Icons(True) 'True = Big icons, False = small icons
ListView1.LargeImageList = Icons.LargeIcons
Dim item1 As New ListViewItem("file1.txt")
item1.ImageIndex = Icons.GetIconIndex("C:\file1.txt")
ListView1.Items.Add(item1)
If you have a file named 'file1.txt' in your C:\ directory, it will load the correct icon and add it to a ListView named ListView1.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Listview imagenlist icons
AnoPem
MrAksel wrote:
Do you see the file Icons.vb? You can use that class to get the icon from a file.
Code: Select all
Dim Icons As New Icons(True) 'True = Big icons, False = small icons
ListView1.LargeImageList = Icons.LargeIcons
Dim item1 As New ListViewItem("file1.txt")
item1.ImageIndex = Icons.GetIconIndex("C:\file1.txt")
ListView1.Items.Add(item1)
If you have a file named 'file1.txt' in your C:\ directory, it will load the correct icon and add it to a ListView named ListView1.
Is it possible when you click a button that have a folderbrowsedialog it will show the icons after the folder has been choosen ? so it will work as the file you posted? just without the treeview
https://t.me/pump_upp
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Listview imagenlist icons
MrAksel
Code: Select all
Dim icons As New Icons(True)
ListView1.LargeImageList = icons.LargeIcons
Dim browser As New FolderBrowserDialog
If browser.ShowDialog() = DialogResult.OK Then
   For Each f As String In System.IO.Directory.GetFiles(browser.SelectedPath)
      Dim Item As New ListViewItem(System.IO.Path.GetFileName(f))
      Item.ImageIndex = icons.GetIconIndex(f)
      ListView1.Items.Add(Item)
   Next
End If
You could have that in a button, as long as you add the class Icons.vb from the file I uploaded to your project. I think it works, but I didn't test it.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Listview imagenlist icons
AnoPem
MrAksel wrote:
Code: Select all
Dim icons As New Icons(True)
ListView1.LargeImageList = icons.LargeIcons
Dim browser As New FolderBrowserDialog
If browser.ShowDialog() = DialogResult.OK Then
   For Each f As String In System.IO.Directory.GetFiles(browser.SelectedPath)
      Dim Item As New ListViewItem(System.IO.Path.GetFileName(f))
      Item.ImageIndex = icons.GetIconIndex(f)
      ListView1.Items.Add(Item)
   Next
End If
You could have that in a button, as long as you add the class Icons.vb from the file I uploaded to your project. I think it works, but I didn't test it.
I added this code to my button but no icons did show up and 2 folderbrowse dialogs showed up
https://t.me/pump_upp
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Listview imagenlist icons
MrAksel
Did it show any text at all? Did you have any other code in your button?
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
13 posts Page 1 of 2
Return to “Tutorial Requests”