Results 1 to 2 of 2

Thread: Please, maybe this time...

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Location
    BFE in Oregon
    Posts
    33

    Cool Please, maybe this time? :)

    In the CopyNode function, can someone edit it so it returns the correct node but also saves the .text of the source to a file.
    It would be ideal if this code sample could be re-coded for only one treeview and to output the .text to a file.
    The amount of information that I have in the source treeview is too much to copy to another without the ability to destroy the original which I can't figure out either.
    I've been trying for 3 months and would appreciate a little help with this one.
    The time it takes to do any of these tasks is irrelevant (it takes 30 seconds to populate this treeview now), it can be tuned. I need one of two scenarios...
    1. Copy original to another TreeView while destroying the original making sure that what is in the original is copied to the destination alphabetically by Root.
    2. Copy original to file using same scenario as above.

    Neither scenario should copy by index, as that will not fit the file format.

    TIA

    Code:
    Sub CopyTreeView(objTVSrc As TreeView, objTVDest As TreeView)
      
      'Copies the source treeview to a destination
      'treeview. Assumes that both treeviews use the
      'same (or identical) Imagelists.
      
       Dim nodeRoot As Node
       
       objTVDest.Nodes.Clear
       
       For Each nodeRoot In objTVSrc.Nodes
          If (nodeRoot.Parent Is Nothing) Then
             Call CopyTVParentNode(nodeRoot, objTVDest.Nodes)
          End If
       Next
    
    End Sub
    
    
    Private Sub CopyTVParentNode(nodeParent As Node, nodesDest As Nodes)
    
      'Walks the specified source parent treeview node,
      'and all of it's children nodes, adding them to the
      'specified destination Nodes collection.
      '
      'nodeParent: parent node to walk and copy from
      'nodesDest : destination Nodes collection to copy to
    
       Dim nodeDummy As Node
       Dim nodeChild As Node
      
      'First add the parent node to the destination nodes collection.
       Set nodeDummy = CopyNode(nodeParent, nodesDest)
      
      'Get the current parent node's first child
       Set nodeChild = nodeParent.Child
      
      'Now walk through the current parent node's children
      'appending the current child node's text to the passed string
       Do While Not (nodeChild Is Nothing)
        
         'If the current child node has it's own children...
          If nodeChild.Children Then
          
            'Recursively call this proc copying all of it's children
            '(it becomes the new parent node)
             Call CopyTVParentNode(nodeChild, nodesDest)
        
          Else
            
            'Add the child node to the destination nodes collection.
             Set nodeDummy = CopyNode(nodeChild, nodesDest)
          
          End If
      
         'Get the current child node's next sibling
          Set nodeChild = nodeChild.Next
        
      Loop
      
    End Sub
    
    
    Private Function CopyNode(nodeSrc As Node, nodesDest As Nodes) As Node
      
       With nodeSrc
      
          If (.Parent Is Nothing) Then   'Root node
          
             Set CopyNode = nodesDest.Add(, , _
                                          .Key, .Text, _
                                          .Image, .SelectedImage)
             CopyNode.Expanded = True
        
          Else   'Child node
        
             Set CopyNode = nodesDest.Add(.Parent.Index, _
                                          tvwChild, _
                                          .Key, .Text, _
                                         .Image, .SelectedImage)
             CopyNode.Expanded = True
        
          End If
        
       End With
      
    End Function

    [Edited by Glacius Cool on 09-24-2000 at 08:45 PM]
    Glacius Cool
    Concept Designer
    VB5sp4,VC++6sp3

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    To clear a nodes items you use clear method
    Code:
    treeview1.Nodes.Clear
    To store the items in a file, i have a qwestion, what do you mean by
    Code:
    Neither scenario should copy by index, as that will not fit the file format.
    Since that's the best way to have your tree organized.

    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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