Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. What am I missing here?

What am I missing here?

Scheduled Pinned Locked Moved Visual Basic
helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Darshon
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • D Darshon

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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++

      D 1 Reply Last reply
      0
      • C Christian Graus

        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++

        D Offline
        D Offline
        Darshon
        wrote on last edited by
        #3

        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?

        D 1 Reply Last reply
        0
        • D Darshon

          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?

          D Offline
          D Offline
          Darshon
          wrote on last edited by
          #4

          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.

          C 1 Reply Last reply
          0
          • D Darshon

            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.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            No worries - I just got in and online, but I'm glad you found a solution :-) Christian Graus - Microsoft MVP - C++

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups