Adding Items to Treeview Manually.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    Adding Items to Treeview Manually.

    Select Microsoft windows common controls 6.0 (SP6) from components
    Add a TreeView control to the form.
    Add a ImageList control to the form.
    Add some bitmaps to the imagelist.
    Set the name of image list to the Image List property of the Tree view control.

    Add this sample code to the form
    =============== ==============
    [code=vb]
    Private Sub Form_Load()
    Dim Node1 As Node, Node2 As Node
    Dim Node3 As Node, Node4 As Node

    Set Node1 = tv1.Nodes.Add
    tv1.Nodes(1).Te xt = "Node 1"
    tv1.Nodes(1).Ke y = "Node 1"
    tv1.Nodes(1).Im age = "closed"

    Set Node2 = tv1.Nodes.Add(" Node 1", tvwChild, "Node 2")
    tv1.Nodes(2).Te xt = "Node 2"
    tv1.Nodes(2).Ke y = "Node 2"
    tv1.Nodes(2).Im age = "leaf"

    Set Node3 = tv1.Nodes.Add(" Node 1", tvwChild, "Node 3")
    tv1.Nodes(3).Te xt = "Node 3"
    tv1.Nodes(3).Ke y = "Node 3"
    tv1.Nodes(3).Im age = "closed"

    Set Node4 = tv1.Nodes.Add(" Node 3", tvwChild, "Node 4")
    tv1.Nodes(4).Te xt = "Node 4"
    tv1.Nodes(4).Ke y = "Node 4"
    tv1.Nodes(4).Im age = "leaf"
    End Sub

    Private Sub tv1_Collapse(By Val Node As MSComctlLib.Nod e)
    Node.Image = "closed"
    End Sub

    Private Sub tv1_Expand(ByVa l Node As MSComctlLib.Nod e)
    Node.Image = "open"
    End Sub

    [/code]


    NOTE--open,closed,lea f are the Key peoperty of the images in the image list
Working...