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:
Dim drive As Integer = 0, dir As Integer = 0
For drive = 0 To oDrives.Length - 1
Dim oNode As New TreeNode
Try
oNode.ImageIndex = 3
oNode.SelectedImageIndex = 3
oNode.Text = oDrives(drive).ToString.Substring(0, 2)
tvFolders.Nodes.Add(oNode)
oNode.Nodes.Add("")
Catch ex As Exception
MsgBox("Cannot create initial node: " & ex.ToString)
End Try
Next
End Sub
I will appreciate any ideas on this.
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?
2 Attachment(s)
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.
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?
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?
1 Attachment(s)
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.
Re: Treeview control doesn't show images
Just happened to think this might also be the problem with the treeview. Then again maybe not.
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.
Re: Treeview control doesn't show images
well I completely rebuilt the form and it still doesn't show the images.
Re: Treeview control doesn't show images
I think error is from your image.
Try change another image.
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.