Results 1 to 2 of 2

Thread: [2005] Treeview Icons.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    [2005] Treeview Icons.

    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:
    1. Private Sub bindMyTreeView()
    2.         Dim strSectorsSQL As String = "SELECT * FROM tblContinent"
    3.         Dim strSubSectorSQL As String = "Select * FROM tblRegions"
    4.         Dim dsContinents As New DataSet
    5.         Dim dsRegions As New DataSet
    6.         dsContinents = cls_connMger.ReturnOleDbDataset(strAccessConn, strSectorsSQL, "tblContinent")
    7.         dsRegions = cls_connMger.ReturnOleDbDataset(strAccessConn, strSubSectorSQL, "tblRegions")
    8.         Try
    9.             Dim HeaderNode As TreeNode
    10.             Dim parentNode As TreeNode
    11.             Dim childNode As TreeNode
    12.             Dim searchIDNode As TreeNode
    13.             Dim dbRow As DataRow
    14.  
    15.             HeaderNode = tvwPopPlaces.Nodes.Add("CONTINENTS")
    16.             HeaderNode.Tag = "H"
    17.             For Each dbRow In dsContinents.Tables("tblContinent").Rows
    18.                 'For Each searchIDNode In tvwSectors.Nodes
    19.                 'If CStr(searchIDNode.Tag) = "H" Then
    20.                 parentNode = tvwPopPlaces.Nodes.Add(dbRow("ct_Name"))
    21.                 parentNode.Tag = dbRow("ct_ID") '& "C"
    22.                 parentNode.ImageIndex = 0
    23.                 'End If
    24.                 ' Next
    25.             Next
    26.  
    27.             For Each dbRow In dsRegions.Tables("tblRegions").Rows
    28.                 For Each searchIDNode In tvwPopPlaces.Nodes
    29.                     'If CStr(searchIDNode.Tag).EndsWith("C") Then
    30.                     'If Not IsDBNull(parentRow("ct_ID")) Then
    31.                     If Val(searchIDNode.Tag) = dbRow("ct_ID") Then
    32.                         childNode = searchIDNode.Nodes.Add(dbRow("rg_Name"))
    33.                         childNode.Tag = dbRow("rg_ID") ' & "U"
    34.                         childNode.ImageIndex = 2
    35.                     End If
    36.                     'End If
    37.                     'End If
    38.                 Next
    39.             Next
    40.  
    41.             ' HeaderNode = tvwPopPlaces.Nodes.Add("POPULATION")
    42.             'HeaderNode.Tag = "P"
    43.         Catch ex As System.Exception
    44.             MsgBox("Error!" & ex.Message)
    45.         End Try
    46.     End Sub
    47.  
    48.  
    49.     Private Sub tvwPopPlaces_BeforeCollapse(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles tvwPopPlaces.BeforeCollapse
    50.         'When a node is collapsed we want to close the folder icon for the node.
    51.         e.Node.ImageIndex = 0
    52.         e.Node.SelectedImageIndex = 0
    53.     End Sub
    54.  
    55.     Private Sub tvwPopPlaces_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles tvwPopPlaces.BeforeExpand
    56.         If e.Node.ImageIndex = 2 Then Exit Sub
    57.  
    58.         Try
    59.             If e.Node.GetNodeCount(False) = 1 And e.Node.Nodes(0).Text = "" Then
    60.                 e.Node.Nodes(0).Remove()
    61.             End If
    62.         Catch ex As Exception
    63.             MsgBox("Unable to expand " & e.Node.FullPath & ":" & ex.ToString)
    64.         End Try
    65.  
    66.         If e.Node.GetNodeCount(False) > 0 Then
    67.             e.Node.ImageIndex = 1
    68.             e.Node.SelectedImageIndex = 1
    69.         End If
    70.     End Sub
    Attached Images Attached Images   

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [2005] Treeview Icons.

    Ok got it.
    I included
    childNode.SelectedImageIndex = 2 in the bindMyTreeView() sub. but i still have a lack of confidence demon here. If there is any more logical way of doing it. Please feel free to post it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width