Results 1 to 3 of 3

Thread: TreeView (The Basics Sir)

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    1

    Exclamation

    I am a complete idiot at Visual Basic..

    I would like to create a Tree View Structure like the one in Windows Explorer but I will customize it to use like a family tree.

    I tried getting some information from the Posts over here of how to create it but I couldn't make any head or tail of it.

    could somebody please give me a working sample code for such a tree so that I could then make additions to it or customize it as I may want..

    Regards,

    omerkh
    http://www.khyber.org

  2. #2
    Lively Member
    Join Date
    Nov 2000
    Posts
    82
    I'm emailing you a form. This form uses Sheridan's Tree View (SSTree), rather than MS's TreeView. You'll not be able to view the TreeView contriol, but you can read the code and get an idea as to what's going on.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    Treeviews are a pain in the ass... here is the basics as I see it...

    Code:
    '---------------------------------'
    '-- logic of the tree structure --'
    '-- root = A0 top of the tree   --'
    '-- 1st child# = B# next branch --'
    '-- 2nd child# = C# next branch --'
    '--            etc...           --'
    '-- ::example::                 --'
    '-- A0                          --'
    '-- +..B1                       --'
    '-- |  +..C1                    --'
    '-- |                           --'
    '-- +..B2                       --'
    '--    +..C2                    --'
    '--    +..C3                    --'
    '---------------------------------'
    
    Public Type TV_struct
      indent As Integer
      label  As String
    end Type
    
    Public Sub SetupTree(ByRef tv As TreeView, ByRef tv_list() As TV_struct)
    
      Dim nodX         As Node    '' new node for the tree structure, (not really needed?).
      Dim ChildStr     As String  '' current child ASCII tree index. EX: B
      Dim Child        As String  '' current child ASCII-numeric tree index Code. EX: B1
      Dim ChildCount   As Long    '' current count on the specific child.
      Dim levelCnt(26) As Long    '' record of current child values.
      Dim i            As Long    '' general counter
      Dim Subset       As String  '' defines what subset the new label should go under.
      Dim SubsetStr    As String
      Dim SubsetCount  As Long    '' number of subsets
      
      '' make sure the tree has no existing nodes and is visible
      Call tv.ZOrder(vbBringToFront)
      Call tv.Nodes.Clear
      
      '' make sure the tree is visible
      tv.Visible = True
      
      '' setup inital values for the tree structure
      Set nodX = tv.Nodes.Add(, , "A0", "GENERAL LABEL")
      
      For i = LBound(tv_list) To UBound(tv_list) Step 1
        
        '' Get the Alpha Indent 'B' to 'Z'
        ChildStr = Chr$(65 + tv_list(i).indent)
        
        '' record the next available spot for the Alpha Indent
        '' 0 -> 65K
        levelCnt(Asc(ChildStr) - 64) = levelCnt(Asc(ChildStr) - 64) + 1
        ChildCount = levelCnt(Asc(ChildStr) - 64)
        
        '' cat the final level ie B1
        Child = ChildStr & ChildCount
        
        '' determine what subset it is
        SubsetStr = Chr$(64 + tv_list(i).indent)
        SubsetCount = levelCnt(Asc(SubsetStr) - 64)
        Subset = SubsetStr & SubsetCount
                
        '' add the node to the treeview
        Set nodX = tv.Nodes.Add(Subset, tvwChild, Child, tv_list(i).label)
        
      Next i
    
    End Sub
    well, that's what worked for me.. so do what you want with it. It has it's limitations, but they are fixable. I probably forgot something in this example, so don't get all pissed if something doesn't work right.
    -Shickadance

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