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