Listview and Krypton help - Printable Version +- BP Forums (https://bpforums.info) +-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55) +--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56) +---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8) +----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=9) +----- Thread: Listview and Krypton help (/showthread.php?tid=685) |
Listview and Krypton help - brco900033 - 10-26-2012 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! Re: Listview and Krypton help - Snake_eyes - 11-01-2012 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 |