11-01-2012, 01:04 AM
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
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...