TreeView Example
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: TreeView Example

  1. #1
    Join Date
    Feb 2000
    Location
    America
    Posts
    130

    TreeView Example

    Does anyone know where I can find an example of the TreeView? I need to know how to add roots and subroots, etc. And how to check the value of a seleted root. Any suggestions? Thanx


  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: TreeView Example

    First off, try the MSDN. There's a real good example at
    http://www.stlvbug.org
    Click on "View Code Online" and then look toward the bottom of the page, there is a Intro Session from the February meeting that covers the Tree View control.

    good luck,
    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: TreeView Example

    Here's some example code of populating a TreeView with 5 root nodes, 5 children and some grandchild nodes :


    private Sub Form_Load()
    '
    Dim i as Integer
    '
    ' Add some root level items
    '
    for i = 1 to 5
    TreeView1.Nodes.Add , , "ROOT" & i, "Root Item " & i
    next
    '
    ' Now add some children
    '
    for i = 1 to 5
    With TreeView1.Nodes
    .Add "ROOT1", tvwChild, "ROOT1CHILD" & i, "Child Item " & i
    .Add "ROOT2", tvwChild, "ROOT2CHILD" & i, "Child Item " & i
    .Add "ROOT3", tvwChild, "ROOT3CHILD" & i, "Child Item " & i
    .Add "ROOT4", tvwChild, "ROOT4CHILD" & i, "Child Item " & i
    .Add "ROOT5", tvwChild, "ROOT5CHILD" & i, "Child Item " & i
    End With
    next
    '
    ' Now Add Some Grand-Children
    '
    for i = 1 to 5
    With TreeView1.Nodes
    .Add "ROOT1CHILD2", tvwChild, , "Grand Child " & i
    .Add "ROOT2CHILD2", tvwChild, , "Grand Child " & i
    .Add "ROOT3CHILD2", tvwChild, , "Grand Child " & i
    .Add "ROOT4CHILD2", tvwChild, , "Grand Child " & i
    .Add "ROOT5CHILD2", tvwChild, , "Grand Child " & i
    End With
    next
    End Sub




    To find the value of the selected node, you can use the 'TreeView1.SelectedItem' object - that returns a 'node' pointer to the selected node.


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  4. #4
    Join Date
    Feb 2000
    Location
    America
    Posts
    130

    Re: TreeView Example

    Thanx! This is exactly the kind of example I needed.


Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center