Solved

TreeView - Silly Question

Posted on 2000-04-22
14
287 Views
Last Modified: 2007-10-18
I have a TreeView program. But it only shows the Open Folder
picture on folders that are selected. Even if I leave a folder open
with all it's children showing underneath it still only shows the
folder thats "selected" as being open.

Must be some dumb way to make it show an Open Folder picture
if you leave that node and it's children open!

Also, I added a third icon that shows a picture of a paper note.
I can add this as a nodes picture, and it shows as a paper note
while it's "selected". But the moment I click on another folder
it too changes to a closed folder.

What code do I add where to fix this!

P.S. I know it's not my code doing this because I deleted just about everything to make sure it wasn't. Seems built in, or missing as the case may be!   VB6



0
Comment
Question by:jgore
  • 7
  • 3
  • 2
  • +2
14 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2741067
What is your code in the doubleclick event of your treeview?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2741071
just to give you an idea this is how i load my images and respond to them and it seems to work ok:


Private Sub Form_Load()
    Dim imgI As ListImage
    Set imgI = ImageList1.ListImages.Add(, "open", LoadPicture("C:\My Documents\VB Projects\Desktop\Programs\FTP\open.bmp"))
    Set imgI = ImageList1.ListImages.Add(, "closed", LoadPicture("C:\My Documents\VB Projects\Desktop\Programs\FTP\closed.bmp"))
    TreeView1.ImageList = ImageList1
    TreeView1.Style = tvwTreelinesPictureText
    TreeView1.Nodes.Add , , "Parent", "Operations", "closed"
    TreeView1.Nodes.Add "Parent", tvwChild, "Op1", "West Coast", "closed"
    TreeView1.Nodes.Add "Parent", tvwChild, "Op2", "East Coast", "closed"
    TreeView1.Nodes.Add "Op1", tvwChild, , "California", "closed"
    TreeView1.Nodes.Add "Op2", tvwChild, , "New York", "closed"
    TreeView1.Nodes.Add "Op2", tvwChild, , "Boston", "closed"
End Sub


Private Sub TreeView1_DblClick()
    If TreeView1.SelectedItem.Image = "closed" Then
        TreeView1.SelectedItem.Image = "open"
    Else
        TreeView1.SelectedItem.Image = "closed"
    End If
End Sub

0
 
LVL 1

Expert Comment

by:okcman
ID: 2741075
I can only presume that you are using a
image list ,if so maybe you can pick out the code you need from this one that is connecting to a database, the selection depends on a how you define the "view" object of the treeview node and how you are changing your selection of nodes. hope this helps



Option Explicit
'
'
Private mconCurrent As New ADODB.Connection
Private mcmdCurrent As New ADODB.Command

'
' Form level variable to store a reference to the root node.
Private mnodRoot As Node

'
' When the form is loaded, open the database connection
' and call the InitTree procedure to initialize the TreeView
' control instance.
Private Sub Form_Load()
    mconCurrent.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.3.51;" & _
        "Persist Security Info=False;" & _
        "Data Source=" & App.Path & "\ETC.mdb"
    mconCurrent.Open
    Set mcmdCurrent.ActiveConnection = mconCurrent
    Call InitTree
End Sub

'
' Initialize the root node. This node will have 10 child nodes;
' One for each office. After adding the root node, initialize the
' office nodes. Finally, expand the folders and sort the nodes.
Private Sub InitTree()
    Set mnodRoot = tvwETC.Nodes.Add _
    (, , "Root", "Offices", "SmallClsdfold", _
        "SmallOpenfold")
    Call InitTreeOffice(mnodRoot)
    mnodRoot.Expanded = True
    '
    ' The child nodes are sorted after they have been added. Sorting
    ' the child nodes forst will not cause them to be sorted.
    mnodRoot.Sorted = True

End Sub

' Initialize the office nodes. Office nodes ar added as children of
' the root node (passed as an argument in proot)
'
' Open a recordset based upon tblOffices. For each office, add the
' node. After adding all of the offices, sort the nodes.
Private Sub InitTreeOffice(pnodRoot As Node)
    Dim prstCurrent As New ADODB.Recordset
    Dim pnodCurrent As Node
    mcmdCurrent.CommandType = adCmdTable
    mcmdCurrent.CommandText = "tblOffices"
    Set prstCurrent = mcmdCurrent.Execute
    Do Until prstCurrent.EOF
        Set pnodCurrent = _
            tvwETC.Nodes.Add(pnodRoot, tvwChild)
        ' The following information could have been specified
        ' on the call to the Add method.
        With pnodCurrent
            .Text = prstCurrent("fldOfficeDescription")
            .Image = "SmallClsdfold"
            .ExpandedImage = "SmallOpenfold"
        End With
        '
        ' For the current office, initialize the department nodes.
        Call InitTreeDepartment(pnodCurrent, prstCurrent("fldOfficeID"))
        '
        ' After reading the departments pertaining to the current
        ' office, sort them.
        pnodCurrent.Sorted = True
        prstCurrent.MoveNext
    Loop
End Sub
'
' Initialize the department nodes. each office has one or more departments.
' The procedure is similar to InitTreeOffice. The departments pertaining
' to a particular office are selected than added as children of the
' current department
Private Sub InitTreeDepartment(pnodParent As Node, plngOfficeID As Long)
    Dim pnodCurrent As Node
    Dim prstCurrent As Recordset
    '
    ' Select the departments pertaining to the current office.
    mcmdCurrent.CommandType = adCmdText
    mcmdCurrent.CommandText = _
        "SELECT * FROM tblDepartments " & _
        "WHERE fldOfficeID = " & plngOfficeID
    Set prstCurrent = mcmdCurrent.Execute
    Do Until prstCurrent.EOF
        Set pnodCurrent = tvwETC.Nodes.Add(pnodParent, _
            tvwChild)
        With pnodCurrent
            .Text = prstCurrent("fldDepartmentDescription")
            .Image = "SmallClsdfold"
            .ExpandedImage = "SmallOpenfold"
            '
            ' Setting the Tag property here is ciriical given
            ' the program's implementation. Only department nodes have
            ' the Tag property set. This property is used to determine
            ' whether or not the ListView control needs to updated when
            ' a node is clicked.
            .Tag = prstCurrent("fldDepartmentID")
        End With
        '
        ' Initialize the employees pertaining to the current
        ' department
        Call InitTreeEmployee(pnodCurrent, _
            prstCurrent("fldDepartmentID"))
        pnodCurrent.Sorted = True
        prstCurrent.MoveNext
    Loop
End Sub
'
' The employees are the leaves in the hierarchy. This procedure is similar
' to the InitTreeDepartment procedure.
Private Sub InitTreeEmployee(pnodParent As Node, pintDepartmentID As Integer)
On Error GoTo No_Record
    Dim pnodCurrent As Node
    Dim prstCurrent As ADODB.Recordset
    '
    ' Select the employees that work in the current department.
    mcmdCurrent.CommandType = adCmdText
    mcmdCurrent.CommandText = _
        "SELECT * FROM tblEmployees " & _
        "WHERE fldDepartmentID = " & pintDepartmentID
    Set prstCurrent = mcmdCurrent.Execute
    Do Until prstCurrent.EOF
        Set pnodCurrent = _
            tvwETC.Nodes.Add(pnodParent, tvwChild)
        pnodCurrent.Text = prstCurrent("fldName")
        If prstCurrent("fldInOut") = True Then
            pnodCurrent.Image = "SmallPhone07"
        Else
            pnodCurrent.Image = "SmallPhone08"
        End If
        prstCurrent.MoveNext
    Loop
No_Record:
End Sub

Private Sub lvwEmployees_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    lvwEmployees.Sorted = True
    lvwEmployees.SortKey = ColumnHeader.Index - 1
End Sub

'
' Examine the Nodes collection and collapse each node.
Private Sub mnuDisplayCollapse_Click()
    Dim pnodCurrent As Node
    For Each pnodCurrent In tvwETC.Nodes
        pnodCurrent.Expanded = False
    Next
End Sub

'
' Examine the Nodes collection and expand each node.
Private Sub mnuDisplayExpand_Click()
    Dim pnodCurrent As Node
    For Each pnodCurrent In tvwETC.Nodes
        pnodCurrent.Expanded = True
    Next
End Sub

Private Sub mnuDisplayLeft_Click()
    lvwEmployees.Arrange = lvwAutoLeft
End Sub

Private Sub mnuDisplayTop_Click()
    lvwEmployees.Arrange = lvwAutoTop
End Sub

Private Sub mnuFileExit_Click()
    Unload Me
End Sub

'
' Traverse the hierarchy of notes. This procedure contains three
' nested for loops to examine each level of the hierarchy.
Private Sub mnuFilePrint_Click()
    Dim pnodOffice As Node, pnodDept As Node, _
        pnodEmp As Node
    Dim pintRC As Integer, pintOC As Integer, _
        pintDC As Integer
    Dim pintRcount As Integer, pintOCount As Integer, _
        pintDCount As Integer
    Printer.Print mnodRoot.Text
    Set pnodOffice = mnodRoot.Child
    pintRC = mnodRoot.Children
    '
    ' Examine each office
    For pintRcount = 1 To pintRC
        Printer.Print "     "; pnodOffice.Text
        Set pnodDept = pnodOffice.Child
        pintOC = pnodOffice.Children
        '
        ' Examine the departments pertaining to the current office.
        For pintOCount = 1 To pintOC
            Printer.Print "        "; pnodDept.Text
            Set pnodEmp = pnodDept.Child
            pintDC = pnodDept.Children
            '
            ' Examine the employees pertaining to the current dept.
            For pintDCount = 1 To pintDC
                Printer.Print "            "; _
                    pnodEmp.Text
                Set pnodEmp = pnodEmp.Next
            Next
            Set pnodDept = pnodDept.Next
        Next
        Set pnodOffice = pnodOffice.Next
    Next
    Printer.EndDoc
End Sub

Private Sub mnuViewSet_Click(Index As Integer)
    Select Case Index
        Case 0
            lvwEmployees.View = lvwIcon
        Case 1
            lvwEmployees.View = lvwSmallIcon
        Case 2
            lvwEmployees.View = lvwList
        Case 3
            lvwEmployees.View = lvwReport
    End Select
End Sub

Private Sub tvwETC_NodeClick(ByVal Node As MSComctlLib.Node)
    If Node.Tag <> vbNullString Then
        Call InitializeList(Node.Tag)
    Else
        ClearList
    End If
End Sub

'
' Clear the contents of the ListView control.
Private Sub ClearList()
    lvwEmployees.ListItems.Clear
End Sub

'
' This procedure executes when the user clicks on a department level
' node (one that has its Tag property set to something other than
' an empty string.
'
' The procedure performs a complete initialization of the ListView
' control based upon the currently selected department.
Private Sub InitializeList(pintID As Integer)
    Dim pitmCurrent As ListItem
    Dim prstCurrent As New ADODB.Recordset
    mcmdCurrent.CommandType = adCmdText
    mcmdCurrent.CommandText = _
        "SELECT * FROM tblEmployees " & _
        "WHERE fldDepartmentID = " & pintID
    Set prstCurrent = mcmdCurrent.Execute
    lvwEmployees.Icons = ilsLargeIcons
    lvwEmployees.SmallIcons = ilsSmallIcons
    lvwEmployees.View = lvwIcon
    lvwEmployees.ListItems.Clear
    lvwEmployees.ColumnHeaders.Add , , "Name", 1400
    lvwEmployees.ColumnHeaders.Add , , "Phone", 1500
    lvwEmployees.ColumnHeaders.Add , , "Ext.", 1000
    Do Until prstCurrent.EOF
        Set pitmCurrent = _
            lvwEmployees.ListItems.Add()
        pitmCurrent.Text = prstCurrent("fldName")
        If prstCurrent("fldInOut") = True Then
            pitmCurrent.SmallIcon = "SmallPhone07"
            pitmCurrent.Icon = "LargePhone07"
        Else
            pitmCurrent.SmallIcon = "SmallPhone08"
            pitmCurrent.Icon = "LargePhone08"
        End If
        pitmCurrent.ListSubItems.Add , "Phone", _
            prstCurrent("fldPhone")
        pitmCurrent.ListSubItems.Add , "Extension", _
            prstCurrent("fldExtension")
        prstCurrent.MoveNext
    Loop
End Sub
0
 
LVL 1

Expert Comment

by:okcman
ID: 2741079
I can only presume that you are using a
image list ,if so maybe you can pick out the code you need from this one that is connecting to a database, the selection depends on a how you define the "view" object of the treeview node and how you are changing your selection of nodes. hope this helps



Option Explicit
'
'
Private mconCurrent As New ADODB.Connection
Private mcmdCurrent As New ADODB.Command

'
' Form level variable to store a reference to the root node.
Private mnodRoot As Node

'
' When the form is loaded, open the database connection
' and call the InitTree procedure to initialize the TreeView
' control instance.
Private Sub Form_Load()
    mconCurrent.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.3.51;" & _
        "Persist Security Info=False;" & _
        "Data Source=" & App.Path & "\ETC.mdb"
    mconCurrent.Open
    Set mcmdCurrent.ActiveConnection = mconCurrent
    Call InitTree
End Sub

'
' Initialize the root node. This node will have 10 child nodes;
' One for each office. After adding the root node, initialize the
' office nodes. Finally, expand the folders and sort the nodes.
Private Sub InitTree()
    Set mnodRoot = tvwETC.Nodes.Add _
    (, , "Root", "Offices", "SmallClsdfold", _
        "SmallOpenfold")
    Call InitTreeOffice(mnodRoot)
    mnodRoot.Expanded = True
    '
    ' The child nodes are sorted after they have been added. Sorting
    ' the child nodes forst will not cause them to be sorted.
    mnodRoot.Sorted = True

End Sub

' Initialize the office nodes. Office nodes ar added as children of
' the root node (passed as an argument in proot)
'
' Open a recordset based upon tblOffices. For each office, add the
' node. After adding all of the offices, sort the nodes.
Private Sub InitTreeOffice(pnodRoot As Node)
    Dim prstCurrent As New ADODB.Recordset
    Dim pnodCurrent As Node
    mcmdCurrent.CommandType = adCmdTable
    mcmdCurrent.CommandText = "tblOffices"
    Set prstCurrent = mcmdCurrent.Execute
    Do Until prstCurrent.EOF
        Set pnodCurrent = _
            tvwETC.Nodes.Add(pnodRoot, tvwChild)
        ' The following information could have been specified
        ' on the call to the Add method.
        With pnodCurrent
            .Text = prstCurrent("fldOfficeDescription")
            .Image = "SmallClsdfold"
            .ExpandedImage = "SmallOpenfold"
        End With
        '
        ' For the current office, initialize the department nodes.
        Call InitTreeDepartment(pnodCurrent, prstCurrent("fldOfficeID"))
        '
        ' After reading the departments pertaining to the current
        ' office, sort them.
        pnodCurrent.Sorted = True
        prstCurrent.MoveNext
    Loop
End Sub
'
' Initialize the department nodes. each office has one or more departments.
' The procedure is similar to InitTreeOffice. The departments pertaining
' to a particular office are selected than added as children of the
' current department
Private Sub InitTreeDepartment(pnodParent As Node, plngOfficeID As Long)
    Dim pnodCurrent As Node
    Dim prstCurrent As Recordset
    '
    ' Select the departments pertaining to the current office.
    mcmdCurrent.CommandType = adCmdText
    mcmdCurrent.CommandText = _
        "SELECT * FROM tblDepartments " & _
        "WHERE fldOfficeID = " & plngOfficeID
    Set prstCurrent = mcmdCurrent.Execute
    Do Until prstCurrent.EOF
        Set pnodCurrent = tvwETC.Nodes.Add(pnodParent, _
            tvwChild)
        With pnodCurrent
            .Text = prstCurrent("fldDepartmentDescription")
            .Image = "SmallClsdfold"
            .ExpandedImage = "SmallOpenfold"
            '
            ' Setting the Tag property here is ciriical given
            ' the program's implementation. Only department nodes have
            ' the Tag property set. This property is used to determine
            ' whether or not the ListView control needs to updated when
            ' a node is clicked.
            .Tag = prstCurrent("fldDepartmentID")
        End With
        '
        ' Initialize the employees pertaining to the current
        ' department
        Call InitTreeEmployee(pnodCurrent, _
            prstCurrent("fldDepartmentID"))
        pnodCurrent.Sorted = True
        prstCurrent.MoveNext
    Loop
End Sub
'
' The employees are the leaves in the hierarchy. This procedure is similar
' to the InitTreeDepartment procedure.
Private Sub InitTreeEmployee(pnodParent As Node, pintDepartmentID As Integer)
On Error GoTo No_Record
    Dim pnodCurrent As Node
    Dim prstCurrent As ADODB.Recordset
    '
    ' Select the employees that work in the current department.
    mcmdCurrent.CommandType = adCmdText
    mcmdCurrent.CommandText = _
        "SELECT * FROM tblEmployees " & _
        "WHERE fldDepartmentID = " & pintDepartmentID
    Set prstCurrent = mcmdCurrent.Execute
    Do Until prstCurrent.EOF
        Set pnodCurrent = _
            tvwETC.Nodes.Add(pnodParent, tvwChild)
        pnodCurrent.Text = prstCurrent("fldName")
        If prstCurrent("fldInOut") = True Then
            pnodCurrent.Image = "SmallPhone07"
        Else
            pnodCurrent.Image = "SmallPhone08"
        End If
        prstCurrent.MoveNext
    Loop
No_Record:
End Sub

Private Sub lvwEmployees_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    lvwEmployees.Sorted = True
    lvwEmployees.SortKey = ColumnHeader.Index - 1
End Sub

'
' Examine the Nodes collection and collapse each node.
Private Sub mnuDisplayCollapse_Click()
    Dim pnodCurrent As Node
    For Each pnodCurrent In tvwETC.Nodes
        pnodCurrent.Expanded = False
    Next
End Sub

'
' Examine the Nodes collection and expand each node.
Private Sub mnuDisplayExpand_Click()
    Dim pnodCurrent As Node
    For Each pnodCurrent In tvwETC.Nodes
        pnodCurrent.Expanded = True
    Next
End Sub

Private Sub mnuDisplayLeft_Click()
    lvwEmployees.Arrange = lvwAutoLeft
End Sub

Private Sub mnuDisplayTop_Click()
    lvwEmployees.Arrange = lvwAutoTop
End Sub

Private Sub mnuFileExit_Click()
    Unload Me
End Sub

'
' Traverse the hierarchy of notes. This procedure contains three
' nested for loops to examine each level of the hierarchy.
Private Sub mnuFilePrint_Click()
    Dim pnodOffice As Node, pnodDept As Node, _
        pnodEmp As Node
    Dim pintRC As Integer, pintOC As Integer, _
        pintDC As Integer
    Dim pintRcount As Integer, pintOCount As Integer, _
        pintDCount As Integer
    Printer.Print mnodRoot.Text
    Set pnodOffice = mnodRoot.Child
    pintRC = mnodRoot.Children
    '
    ' Examine each office
    For pintRcount = 1 To pintRC
        Printer.Print "     "; pnodOffice.Text
        Set pnodDept = pnodOffice.Child
        pintOC = pnodOffice.Children
        '
        ' Examine the departments pertaining to the current office.
        For pintOCount = 1 To pintOC
            Printer.Print "        "; pnodDept.Text
            Set pnodEmp = pnodDept.Child
            pintDC = pnodDept.Children
            '
            ' Examine the employees pertaining to the current dept.
            For pintDCount = 1 To pintDC
                Printer.Print "            "; _
                    pnodEmp.Text
                Set pnodEmp = pnodEmp.Next
            Next
            Set pnodDept = pnodDept.Next
        Next
        Set pnodOffice = pnodOffice.Next
    Next
    Printer.EndDoc
End Sub

Private Sub mnuViewSet_Click(Index As Integer)
    Select Case Index
        Case 0
            lvwEmployees.View = lvwIcon
        Case 1
            lvwEmployees.View = lvwSmallIcon
        Case 2
            lvwEmployees.View = lvwList
        Case 3
            lvwEmployees.View = lvwReport
    End Select
End Sub

Private Sub tvwETC_NodeClick(ByVal Node As MSComctlLib.Node)
    If Node.Tag <> vbNullString Then
        Call InitializeList(Node.Tag)
    Else
        ClearList
    End If
End Sub

'
' Clear the contents of the ListView control.
Private Sub ClearList()
    lvwEmployees.ListItems.Clear
End Sub

'
' This procedure executes when the user clicks on a department level
' node (one that has its Tag property set to something other than
' an empty string.
'
' The procedure performs a complete initialization of the ListView
' control based upon the currently selected department.
Private Sub InitializeList(pintID As Integer)
    Dim pitmCurrent As ListItem
    Dim prstCurrent As New ADODB.Recordset
    mcmdCurrent.CommandType = adCmdText
    mcmdCurrent.CommandText = _
        "SELECT * FROM tblEmployees " & _
        "WHERE fldDepartmentID = " & pintID
    Set prstCurrent = mcmdCurrent.Execute
    lvwEmployees.Icons = ilsLargeIcons
    lvwEmployees.SmallIcons = ilsSmallIcons
    lvwEmployees.View = lvwIcon
    lvwEmployees.ListItems.Clear
    lvwEmployees.ColumnHeaders.Add , , "Name", 1400
    lvwEmployees.ColumnHeaders.Add , , "Phone", 1500
    lvwEmployees.ColumnHeaders.Add , , "Ext.", 1000
    Do Until prstCurrent.EOF
        Set pitmCurrent = _
            lvwEmployees.ListItems.Add()
        pitmCurrent.Text = prstCurrent("fldName")
        If prstCurrent("fldInOut") = True Then
            pitmCurrent.SmallIcon = "SmallPhone07"
            pitmCurrent.Icon = "LargePhone07"
        Else
            pitmCurrent.SmallIcon = "SmallPhone08"
            pitmCurrent.Icon = "LargePhone08"
        End If
        pitmCurrent.ListSubItems.Add , "Phone", _
            prstCurrent("fldPhone")
        pitmCurrent.ListSubItems.Add , "Extension", _
            prstCurrent("fldExtension")
        prstCurrent.MoveNext
    Loop
End Sub
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2741089
Now that you have deleted everything.. post your code.. <smile>.

Also, if you haven't updated your VB with Service Pack 3.. get it done.
0
 

Author Comment

by:jgore
ID: 2741285
Neither of those help much.
I cut my code down so I'll paste it.  
Most of it is commented out.

No matter what I do it closes the other
folders. I can't leave folders open. That is, they are open, but the PICTURE shows them closed.


Option Explicit

Dim NbNode As Long
Dim NodeDrag As Node
Dim NodeDrop As Node

Private Sub Form_Load()

End Sub

Private Sub TV_DblClick()
          If TreeView1.SelectedItem.Image = "closed" Then
                 TreeView1.SelectedItem.Image = "open"
          Else
                 TreeView1.SelectedItem.Image = "closed"
          End If
                    End Sub
Private Sub TimerOpenNode_Timer()
 '   On Error Resume Next
 '   TV.DropHighlight.Expanded = True
 '   TimerOpenNode.Enabled = False
End Sub
Private Sub Command1_Click()

    If TV.SelectedItem Is Nothing Then
        TV.Nodes.Add , , CStr(NbNode) & "_key", "Node " & NbNode, 1, 2
    Else
        TV.Nodes.Add TV.SelectedItem.Index, tvwChild, CStr(NbNode) & "_key", "Node " & NbNode, 1, 2
    End If
    NbNode = NbNode + 1

End Sub

Private Sub Command2_Click()
  TV.Nodes.Clear
End Sub
Private Sub TV_DragDrop(Source As Control, x As Single, y As Single)
   
 '   If Source.Tag = "TV" Then
 '
 '       If Not TV.HitTest(x, y) Is Nothing Then
 '           Set NodeDrop = TV.HitTest(x, y)
 '       End If
 '
 '       If Not (NodeDrag Is Nothing And NodeDrop Is Nothing) Then
 '           NodeDrop.Expanded = True
 '           If Not DragAndDrop(TV, NodeDrag, NodeDrop) Then MsgBox "Impossible de le déplacer ici", vbCritical
 '           Set TV.DropHighlight = Nothing
 '       End If
 '
 '   End If
 '
 '   TimerOpenNode.Enabled = False
   
End Sub

Private Sub TV_DragOver(Source As Control, x As Single, y As Single, State As Integer)
 '   If Source.Tag = "TV" Then
 '       Set TV.DropHighlight = TV.HitTest(x, y)
 '       If Not TV.DropHighlight Is Nothing Then
 '           TimerOpenNode.Enabled = False
 '           If TV.DropHighlight.Expanded = False Then
 '               TimerOpenNode.Enabled = True
 '           End If
 '       End If
 '   End If
End Sub

Private Sub TV_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  ' If Not TV.HitTest(x, y) Is Nothing Then
  '      TV.DropHighlight = TV.HitTest(x, y)
  '      Set NodeDrag = TV.HitTest(x, y)
  '  End If
End Sub

Private Sub TV_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'    If Button = 1 Then
'        If Not NodeDrag Is Nothing Then
'            If Not TV.HitTest(x, y) Is Nothing Then
'                If NodeDrag.Index <> TV.HitTest(x, y).Index Then
'                    TV.Drag vbBeginDrag
'                End If
'            End If
'        End If
'    End If
End Sub


0
 

Author Comment

by:jgore
ID: 2741290
Oh, just add two generic buttons, one treeview,
and an imagelist to the above.
note that Treeview is named TV.

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:jgore
ID: 2741292
Hmmmm, even when I fixed the above
TV_DblClick() event it still doesn't work right.

Private Sub TV_DblClick()
          If TV.SelectedItem.Image = "closed" Then
                 TV.SelectedItem.Image = "open"
          Else
                 TV.SelectedItem.Image = "closed"
          End If
 End Sub
0
 
LVL 9

Accepted Solution

by:
kprestage earned 71 total points
ID: 2741802
Use the expanded and collapsed events of the treeview to accomplish this.  Create a form with a Treeview control named "TV" and an Image List named "ImageList1".  Put two images in the image list.  Index 1 is a closed folder, index 2 is an open folder.  Then associate the image list with the treeview.  Then use this code as an example:

'Create 5 nodes and 5 children
Private Sub Form_Load()
For i = 1 To 5
    TV.Nodes.Add , , "Node" & i, "Node Number " & i, 1, 2
Next i

For i = 1 To 5
    TV.Nodes.Add "Node" & i, tvwChild, , "Child of Node " & i, 1, 2
Next i

End Sub

'set the image for collapsed node
Private Sub TV_Collapse(ByVal Node As ComctlLib.Node)
Node.Image = 1
End Sub
'set the image for expanded node
Private Sub TV_Expand(ByVal Node As ComctlLib.Node)
Node.Image = 2
End Sub




'END OF CODE

Now when you expand a node, the image will be set to the open folder, and when it is collapsed, it is returned to a closed folder.

0
 

Author Comment

by:jgore
ID: 2742226
Ohhh, that looks just what I wan't!

What is a COMCTL.LIB ?  I get an error trying
to run the above. I'll search through Components
and see if it's there.
0
 

Author Comment

by:jgore
ID: 2742259
I see, ComctlLib is part of the Windows Common Controls (COMCTL32.OCX ). Which is where TreeView is located.

I also noticed there was more than one in Components!
I'm using:
Microsoft common controls 6 (SP3)
is that wrong?

It just says "User Defined Type Not defined" and then
points to:
Private Sub TV_Collapse(ByVal Node As ComctlLib.Node
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2742264
Private Sub TreeView1_Collapse(ByVal Node As MSComctlLib.Node)

its a built in event for the treeview
0
 

Author Comment

by:jgore
ID: 2742283
I see, ComctlLib is part of the Windows Common Controls (COMCTL32.OCX ). Which is where TreeView is located.

I also noticed there was more than one in Components!
I'm using:
Microsoft common controls 6 (SP3)
is that wrong?

It just says "User Defined Type Not defined" and then
points to:
Private Sub TV_Collapse(ByVal Node As ComctlLib.Node
0
 

Author Comment

by:jgore
ID: 2742367
Thank GOD!   ;-)

OK, now its working perfectly!
The "MSComctlLib.Node" thingy worked.
Thank all of you for your help!

It seemed like such a simple thing but I couldn't find
it in the MS help files, or on the web.  Anyways,
it's all working now and kicking some but!
Cya'z................Jerry




P.S. For Newbies - Web Pages that explain TreeView:

Visual Basic TreeView API Routines
http://www.mvps.org/vbnet/code/comctl/tvcheckbox.htm
Sample Chapter 5:  Controls - TreeView Control
http://www.oreilly.com/catalog/vbcnut/chapter/ch05-tv.html
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now