Murray Brown
asked on
VB.net TreeView image list populating all nodes problem
Hi
I am using the following code to populate a TreeView control in VB.net.
The result is shown on the image below.
For some reason, all the nodes are using the second image "TreeView" when
I don't want them to have any image. All I wanted to populate is cube and only
the bottom one. I don't know why it is in the parent as well
Sub Load_Images()
Dim myImageList As New ImageList()
myImageList.Images.Add(My. Resources. cube)
myImageList.Images.Add(My. Resources. TreeView)
myImageList.Images.Add(My. Resources. TreeView2)
' Assign the ImageList to the TreeView.
Me.TreeView_From.ImageList = myImageList
Me.TreeView_From.Nodes(0). Nodes(2).I mageIndex = 0
End Sub
I am using the following code to populate a TreeView control in VB.net.
The result is shown on the image below.
For some reason, all the nodes are using the second image "TreeView" when
I don't want them to have any image. All I wanted to populate is cube and only
the bottom one. I don't know why it is in the parent as well
Sub Load_Images()
Dim myImageList As New ImageList()
myImageList.Images.Add(My.
myImageList.Images.Add(My.
myImageList.Images.Add(My.
' Assign the ImageList to the TreeView.
Me.TreeView_From.ImageList
Me.TreeView_From.Nodes(0).
End Sub
What are the image indices of the other nodes? Does it work if you set imageindex on one of the nodes to -1?
ASKER
Hi CodeCruiser
The image is populated with the following code that you saw in a different question. Perhaps that will shed some light on the indices
Public Sub Populate_TreeView_From_SQL ()
Dim SQLExpression As String = _
"SELECT TABLE_NAME, COLUMN_NAME FROM information_schema.columns ORDER BY TABLE_NAME,COLUMN_NAME"
Dim Rootnode As TreeNode = Nothing
Dim Mainnode As TreeNode = Nothing
Dim Childnode As TreeNode = Nothing
Dim MainName As String = String.Empty
Dim oConnectionString As String = Me.RichTextBox1.Text
Dim cn As New SqlConnection(oConnectionS tring)
Dim adp As New SqlDataAdapter(SQLExpressi on, cn)
Dim ds As New DataSet
adp.Fill(ds, "SystemData")
Me.TreeView_From.Nodes.Cle ar()
Rootnode = Me.TreeView_From.Nodes.Add (key:="Roo t", text:="database name here", _
imageIndex:=0, selectedImageIndex:=0)
For Each row As DataRow In ds.Tables("SystemData").Ro ws
If MainName <> row(0).ToString Then
Mainnode = Rootnode.Nodes.Add(key:="T able", text:=row(0).ToString, _
imageIndex:=1, selectedImageIndex:=1)
MainName = row(0).ToString
End If
Childnode = Mainnode.Nodes.Add(key:="C olumn", text:=row(1).ToString, _
imageIndex:=2, selectedImageIndex:=2)
Next
Me.TreeView_From.Nodes(0). EnsureVisi ble()
Me.TreeView_From.ExpandAll ()
Me.TreeView_From.Scrollabl e = True
ds.Dispose()
ds = Nothing
adp.Dispose()
adp = Nothing
cn.Dispose()
cn = Nothing
End Sub
The image is populated with the following code that you saw in a different question. Perhaps that will shed some light on the indices
Public Sub Populate_TreeView_From_SQL
Dim SQLExpression As String = _
"SELECT TABLE_NAME, COLUMN_NAME FROM information_schema.columns
Dim Rootnode As TreeNode = Nothing
Dim Mainnode As TreeNode = Nothing
Dim Childnode As TreeNode = Nothing
Dim MainName As String = String.Empty
Dim oConnectionString As String = Me.RichTextBox1.Text
Dim cn As New SqlConnection(oConnectionS
Dim adp As New SqlDataAdapter(SQLExpressi
Dim ds As New DataSet
adp.Fill(ds, "SystemData")
Me.TreeView_From.Nodes.Cle
Rootnode = Me.TreeView_From.Nodes.Add
imageIndex:=0, selectedImageIndex:=0)
For Each row As DataRow In ds.Tables("SystemData").Ro
If MainName <> row(0).ToString Then
Mainnode = Rootnode.Nodes.Add(key:="T
imageIndex:=1, selectedImageIndex:=1)
MainName = row(0).ToString
End If
Childnode = Mainnode.Nodes.Add(key:="C
imageIndex:=2, selectedImageIndex:=2)
Next
Me.TreeView_From.Nodes(0).
Me.TreeView_From.ExpandAll
Me.TreeView_From.Scrollabl
ds.Dispose()
ds = Nothing
adp.Dispose()
adp = Nothing
cn.Dispose()
cn = Nothing
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
http://msdn.microsoft.com/en-us/library/system.windows.forms.treenode.imageindex%28v=vs.71%29.aspx