Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Listview and Krypton help
#1
Hello guys
I'm making a little application that uses a listview. But since I never used the ListView control I don't know much about it, so I have 2 questions. BTW I use DotNetBar ListViewEx if that makes a difference.

How can I add all files from a directory to the listview, with icons. The files are Shortcuts so is the program able to read those kind of files? My second question is how can i get the text from the selected file (file because MultiSelect is disabled), I find it a lot easier with the ListBox but with this application I need the ListView.

How can I get the Krpyton form style programmatically? I thought this was possible?!

Thanks!
#2
I don't know exactly what you mean by "adding files" but if you want to add file names and icons here is what you must do :

Step 1: Import System.IO above your main class
[code2=vbnet]Imports System.IO[/code2]
Step 2: Add an ImageList from the toolbox to your form and set ColorDepth to Depth32Bit
Step 3: Assuming that your listview's view property is set to default (witch is LargeIcon) Search for the LargeImageList property and select the ImageList you just added to your project
Step 4: Now the folowing code snippet should work fine
[code2=vbnet]Try
Dim DirInf As DirectoryInfo = New DirectoryInfo("path to folder")'change it to the actual path of the folder
Dim FileInf As FileInfo
For Each FileInf In DirInf.GetFiles("*.lnk", IO.SearchOption.AllDirectories)
BigImageList.Images.Add(FileInf.Name, Icon.ExtractAssociatedIcon(FileInf.FullName).ToBitmap)
Dim li As New ListViewItem
li.Text = FileInf.Name
li.ImageIndex = CInt(BigImageList.Images.IndexOfKey(FileInf.Name))
ListViewEx1.Items.Add(li)
Next
Catch ex As Exception
End Try[/code2]
Now if you want to show the file full path instead of the file name just change the :
[code2=vbnet]li.Text = FileInf.Name[/code2]
to:
[code2=vbnet]li.Text = FileInf.FullName[/code2]

To get the name of the selected file this code shoul work fine:
[code2=vbnet]Dim li As ListViewItem = ListViewEx1.SelectedItems.Item(0)
MsgBox(li.Name)[/code2]
But beware li.Name is the name of the ListViewItem control witch in this case should be empty if you want the text of the item change it to li.Text

As for the Krypton form style i do not know hot to help you there

Hope the code above Hels you
Sssssssssoftware developer...


Possibly Related Threads…
Thread Author Replies Views Last Post
  Open Zip files into a listview box Worf 2 13,907 09-20-2014, 10:14 AM
Last Post: Worf
  How do I use Listview to delete MySQL DB records kismetgerald 10 33,756 11-28-2012, 05:19 PM
Last Post: brandonio21
  Krypton help brco900033 1 9,305 10-14-2012, 09:13 PM
Last Post: brandonio21
  Krypton Taylor 9 31,219 04-09-2011, 06:51 AM
Last Post: Gamester699

Forum Jump:


Users browsing this thread: 1 Guest(s)