What am I missing here?
-
Hello all, This is my project: I've made a TreeView that displays a folder and all sub folders within it. I also have an AfterSelect sub (Shown below) that looks through the selected directory and displays any files in a ListView. All this works. This is my problem: Although I have an imagelist that is connected to the ListView control, it doesn't show the pictures beside the items when they are listed. All I have is a blank space where the picture should be. And when I try to assign an image to an item through the designer it just ignors them. Probably cause everything I'm doing is through the code view not the designer view. The only thing I can think of is that I'm forgetting to code something to tell the listview to show the images. Can anyone help me out? This is the only code I've written that touches the listview so far.
Private Sub tvwExplorer_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwExplorer.AfterSelect 'Get reference to the selected node Dim dirInfo As DirectoryInfo = New DirectoryInfo(e.Node.FullPath) 'Clear all the items in the listview lvwExplorer.Items.Clear() 'Check if the Directory exist or not If (dirInfo.Exists) Then 'Get reference to all the files Dim fileInfos As FileInfo() = dirInfo.GetFiles() 'Add all the files to the ListView Dim info As FileInfo For Each info In fileInfos Dim item As ListViewItem = New ListViewItem item = lvwExplorer.Items.Add(info.Name) item.SubItems.Add(info.LastAccessTime.ToString()) Next End If End Sub
-
Hello all, This is my project: I've made a TreeView that displays a folder and all sub folders within it. I also have an AfterSelect sub (Shown below) that looks through the selected directory and displays any files in a ListView. All this works. This is my problem: Although I have an imagelist that is connected to the ListView control, it doesn't show the pictures beside the items when they are listed. All I have is a blank space where the picture should be. And when I try to assign an image to an item through the designer it just ignors them. Probably cause everything I'm doing is through the code view not the designer view. The only thing I can think of is that I'm forgetting to code something to tell the listview to show the images. Can anyone help me out? This is the only code I've written that touches the listview so far.
Private Sub tvwExplorer_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwExplorer.AfterSelect 'Get reference to the selected node Dim dirInfo As DirectoryInfo = New DirectoryInfo(e.Node.FullPath) 'Clear all the items in the listview lvwExplorer.Items.Clear() 'Check if the Directory exist or not If (dirInfo.Exists) Then 'Get reference to all the files Dim fileInfos As FileInfo() = dirInfo.GetFiles() 'Add all the files to the ListView Dim info As FileInfo For Each info In fileInfos Dim item As ListViewItem = New ListViewItem item = lvwExplorer.Items.Add(info.Name) item.SubItems.Add(info.LastAccessTime.ToString()) Next End If End Sub
Darshon wrote:
Dim item As ListViewItem = New ListViewItem item = lvwExplorer.Items.Add(info.Name)
This adds a listview item which does not have an image index. You need to build your list view item so that it contains an image index.
Darshon wrote:
Dim item As ListViewItem = New ListViewItem item = lvwExplorer.Items.Add(info.Name)
This makes no sense. You create a new one, then you throw it away to be replaced by the one returned by Add. Christian Graus - Microsoft MVP - C++
-
Darshon wrote:
Dim item As ListViewItem = New ListViewItem item = lvwExplorer.Items.Add(info.Name)
This adds a listview item which does not have an image index. You need to build your list view item so that it contains an image index.
Darshon wrote:
Dim item As ListViewItem = New ListViewItem item = lvwExplorer.Items.Add(info.Name)
This makes no sense. You create a new one, then you throw it away to be replaced by the one returned by Add. Christian Graus - Microsoft MVP - C++
-
Thank you Christian Graus for your comments. I'm fairly new at programing with VB could you give me an example of how you would fix this?
-
Nevermind! :-) I got it to work. I downloaded an example project from this site and looked at how s/he assigned an imagelist to an listviewitem and I got it to work on mine. Thanks for your help.
No worries - I just got in and online, but I'm glad you found a solution :-) Christian Graus - Microsoft MVP - C++