Treenode as image, not text URGENT

S

SeanT

Greetings and salutations! I am having a real issue with the VB.NET
TreeView control. I need to display an image (a.k.a. logo, picture,
etc) from a file as the treenode object. I can not seem to find a way
to do this in .NET. I have tried the DrawImageUnscaled and thought
that was the way to go, but I was wrong. If anyone has any
suggestions, please help! The code I have currently follows:

Public Sub mTreeViewLoad(ByVal m_xmld As XmlDocument)
Try
trvMyList.BeginUpdate()
trvMyList.Nodes.Clear()
<!---code snipped for brevity --->
'loop through the xml and display each node
'all images are strored in an image list with indexes
'and each node text value contains the index to the image

fnRenderImage(trvMyList.Nodes)

trvMyList.SelectedNode = Nothing
trvMyList.EndUpdate()
Catch errorVariable As Exception
Console.WriteLine(errorVariable.Message)
End Try
End Sub

Private Function fnRenderImage(ByVal tnc As TreeNodeCollection)
Try
For Each tn As TreeNode In tnc
Dim x As Integer = tn.Bounds.X
Dim y As Integer = tn.Bounds.Y
If InStr(tn.Text, "_DRAW_IMAGE_") Then
Dim idxImage As Integer 'used to get the index
value from the image list
idxImage = tn.Text.Substring(12)
Dim img As Image =
lstViewerImages.Images(idxImage)
trvMyList.CreateGraphics.DrawImageUnscaled(img, x,
y)
tn.Text = ""
End If
fnRenderImage(tn.Nodes)
Next

Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Function
 
O

One Handed Man \( OHM - Terry Burns \)

Drag an ImageList onto the form, name it myImageList,
set the imagelist property of your Tree to myImageList
Add Images to the image list

To select an image for a Node.

tv.ImageIndex = 1 ' Or whatever the desired image index is

HTH


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
S

SeanT

An ImageList is not what I'm looking for. This creates Icon type
images next to the node values. I need the actual node to paint an
image, not text. Any suggestions? Any one?
 
O

One Handed Man \( OHM - Terry Burns \)

Perhaps I just don't understand you. I thought you wanted an image to appear
where the node is ?, what I told you will do this, where have I
misunderstood you ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
S

SeanT

Where the text for a node appears, I need an image. The solution you
provided is great for icons next to the node, but not to replace the
node text itself with an image. So far, I have only found a third
party control (UltraTree) to do this. I would like to do this myself
and not depend on a 3rd party component.

Thanks,
Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top