I will need some help here.
I have a treeview that loads ok, but i am having a problem on the change of image when i click the last childnode.
just like my first image shows, i have three images. index0 has the ClosedBox,Index1 has the OpenedBox,Index2 has the dot.
When i click on the parent node, it changes from closed to opened and the child should have the dot. This is Ok.
But when i click on the childnode, my dot changes to the closedBox instead of remaining a dot. Of course there is something wrong witth the code, but i cant see it. Below is the code i have and attached are the images of the treeview. Any help will be highly appreciated.
VB Code:
Private Sub bindMyTreeView() Dim strSectorsSQL As String = "SELECT * FROM tblContinent" Dim strSubSectorSQL As String = "Select * FROM tblRegions" Dim dsContinents As New DataSet Dim dsRegions As New DataSet dsContinents = cls_connMger.ReturnOleDbDataset(strAccessConn, strSectorsSQL, "tblContinent") dsRegions = cls_connMger.ReturnOleDbDataset(strAccessConn, strSubSectorSQL, "tblRegions") Try Dim HeaderNode As TreeNode Dim parentNode As TreeNode Dim childNode As TreeNode Dim searchIDNode As TreeNode Dim dbRow As DataRow HeaderNode = tvwPopPlaces.Nodes.Add("CONTINENTS") HeaderNode.Tag = "H" For Each dbRow In dsContinents.Tables("tblContinent").Rows 'For Each searchIDNode In tvwSectors.Nodes 'If CStr(searchIDNode.Tag) = "H" Then parentNode = tvwPopPlaces.Nodes.Add(dbRow("ct_Name")) parentNode.Tag = dbRow("ct_ID") '& "C" parentNode.ImageIndex = 0 'End If ' Next Next For Each dbRow In dsRegions.Tables("tblRegions").Rows For Each searchIDNode In tvwPopPlaces.Nodes 'If CStr(searchIDNode.Tag).EndsWith("C") Then 'If Not IsDBNull(parentRow("ct_ID")) Then If Val(searchIDNode.Tag) = dbRow("ct_ID") Then childNode = searchIDNode.Nodes.Add(dbRow("rg_Name")) childNode.Tag = dbRow("rg_ID") ' & "U" childNode.ImageIndex = 2 End If 'End If 'End If Next Next ' HeaderNode = tvwPopPlaces.Nodes.Add("POPULATION") 'HeaderNode.Tag = "P" Catch ex As System.Exception MsgBox("Error!" & ex.Message) End Try End Sub Private Sub tvwPopPlaces_BeforeCollapse(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles tvwPopPlaces.BeforeCollapse 'When a node is collapsed we want to close the folder icon for the node. e.Node.ImageIndex = 0 e.Node.SelectedImageIndex = 0 End Sub Private Sub tvwPopPlaces_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles tvwPopPlaces.BeforeExpand If e.Node.ImageIndex = 2 Then Exit Sub Try If e.Node.GetNodeCount(False) = 1 And e.Node.Nodes(0).Text = "" Then e.Node.Nodes(0).Remove() End If Catch ex As Exception MsgBox("Unable to expand " & e.Node.FullPath & ":" & ex.ToString) End Try If e.Node.GetNodeCount(False) > 0 Then e.Node.ImageIndex = 1 e.Node.SelectedImageIndex = 1 End If End Sub
