CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2001
    Posts
    4

    treeview control

    HI,
    Is it possible to create a treeview dynamically on run time? The data to
    create the treeview comes from a database and can differ from user to user.
    Thanks in advance.




  2. #2
    Join Date
    Aug 2000
    Location
    England
    Posts
    185

    Re: treeview control

    If yuo place the blank object on the form that you require then the branches can be created dynamically depending on the data to be displayed


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

    Re: treeview control

    sure is - you just have to some data to put in there. Hopefully, you're data will be user specific and have some sort of hierarchical structure that can be easily represented in the tree view control.

    Look into adding things from a recordset first, then start dealing with the recursion - which will be required to build the tree correctly.

    it's pretty easy, once you get used to the routines.

    john

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

  4. #4
    Join Date
    May 2001
    Posts
    4

    Re: treeview control

    Thanks for your help.
    Do you know where I could find some sample code that shows me how to create the treeview during run time?


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

    Re: treeview control

    Here's a very simple example:

    Dim i as Integer
    Dim nod as Node
    Dim nod2 as Node

    TreeView1.Style = tvwTreelinesPlusMinusText
    TreeView1.LineStyle = tvwRootLines

    for i = 1 to 10
    set nod = TreeView1.Nodes.Add(, , , i & "Parent")
    for j = 1 to 3
    set nod2 = TreeView1.Nodes.Add(nod.Index, tvwChild, , "Child" & j)
    for x = 1 to 2
    TreeView1.Nodes.Add nod2.Index, tvwChild, , x & " grandchild"
    next x
    next j
    next i




    this will add some nodes and some child nodes and then some grandchildren nodes to a treeview named TreeView1.

    You can use this as a guide to populating the treeview from a recordset. if you have questions, post them here and someone will help you.

    hope this helps,

    john

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

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

Featured