Results 1 to 11 of 11

Thread: Treeview control doesn't show images

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    19

    Treeview control doesn't show images

    I am trying to setup a treeview control to display all drives and folders on the PC. So far I can display all drives and folders but the images will not show except rarely. I am using an imagelist with 4 images (index 0-3). The code below is used to load the drives in the treeview control. I have tried using every type of image possible from bmp to png and nothing. I have tried the Appllication.EnableVisualStyles() which I now know isn't needed in vs 2008. I am also having problems with a picturebox in another form that shows nothing but a shadow of the image. I suspect this may be a setting somewhere maybe in vs 2008 but am not able to find one.

    Treeview Code:
    1. Dim drive As Integer = 0, dir As Integer = 0
    2.  
    3.         For drive = 0 To oDrives.Length - 1
    4.             Dim oNode As New TreeNode
    5.  
    6.             Try
    7.                 oNode.ImageIndex = 3
    8.                 oNode.SelectedImageIndex = 3
    9.                 oNode.Text = oDrives(drive).ToString.Substring(0, 2)
    10.                 tvFolders.Nodes.Add(oNode)
    11.                 oNode.Nodes.Add("")
    12.  
    13.             Catch ex As Exception
    14.                 MsgBox("Cannot create initial node: " & ex.ToString)
    15.             End Try
    16.         Next
    17.     End Sub

    I will appreciate any ideas on this.

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Treeview control doesn't show images

    Sounds peculiar. first thing I'd do though is get rid of (or at least rearrange) the try...catch block - you should only use them if there is no way of knowing whether an operation will succeed (like for example trying to access a CD drive without knowing if there is a disc in it). This certainly isn't the case for lines like oNode.ImageIndex = 3. Maybe it is when you are testing the ToString of the drive - if that is the case the try..catch should be wrapping just this one line.

    Can you elaborate - when you say the images show rarely.. have you been able to identify any patrern as to in what circumstances the images do show up. As for the picturebox showing only a shadow of an image - it should really be a separate thread, but can you give us a screenshot of what it looks like and another of the actual image as it should show?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    19

    Re: Treeview control doesn't show images

    ok here is the screenshot of the tree control

    and the picturebox that I am having trouble with. The pic to the left is what it should look like. I may do a separate thread on this tho. Just thought they might be related somehow.

    I have not been able to find a pattern as to when the images do show in the treeview except that it will be the first time I run the program but not every time.
    Attached Images Attached Images   

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Treeview control doesn't show images

    I wonder if the ghost image is something to do with the colour depth of the images... try opening the image up in an image editor and reducing changing that and re-trying.

    I'm guessing this ghosting problem only occurs with certain images not all images?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    19

    Re: Treeview control doesn't show images

    I was thinking the same thing and so far I have tried png,jpg,bmp, and gif without success. I haven't tried changing the color depth tho I will give that a try and see what happens. Any ideas on the images in the treeview?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    19

    Re: Treeview control doesn't show images

    As you can see from the screenshot it worked. I changed the mode in photoshop to 8 bits per channel instead of 16. I appreciate your help on this one.
    Attached Images Attached Images  

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    19

    Re: Treeview control doesn't show images

    Just happened to think this might also be the problem with the treeview. Then again maybe not.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    19

    Re: Treeview control doesn't show images

    Well it seems it is not the color depth in the treeview. I have tried all settings from 8 bit to 32 bit without luck. However I did notice the size of the images was 48x48 so I set the imagelist to 48x48 and it worked. After that I went into photoshop and changed the size to 16x16 and tried again. This didn't work. Again I tried the color depth without success. This has really got me baffled.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    19

    Re: Treeview control doesn't show images

    well I completely rebuilt the form and it still doesn't show the images.

  10. #10
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: Treeview control doesn't show images

    I think error is from your image.
    Try change another image.
    --***----------***-----

    If i help you please rate me.

    Working with Excel * Working with String * Working with Database * Working with array *

    K51 ĐH BÁCH KHOA HÀ NỘI - Khoa CNTT pro.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    19

    Re: Treeview control doesn't show images

    I have tried several types of images and none work. I have also tried changing the color depth and resolution without success.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width