Results 1 to 3 of 3

Thread: trouble with treeview and parent/child nodes -

  1. #1

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    trouble with treeview and parent/child nodes -

    Code:
    +root
       +parent1
           -child1
           -child2
       +parent2
       +parent3
            -child1
    using dotNet v2003

    with this example above - how can I determine that parent2 is really a 'parent'?

    also, say i click on 'parent3' node, how can I determine that this is a parent node with children?
    Last edited by ZeBula8; Mar 5th, 2006 at 12:18 AM.

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: trouble with treeview and parent/child nodes -

    VB Code:
    1. Private Sub TreeView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.Click
    2.         Try
    3.             Debug.Print(TreeView1.SelectedNode.Parent.Text)
    4.         Catch
    5.  
    6.         End Try
    7.     End Sub

    All I could get..Im sure someone could do something better..

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: trouble with treeview and parent/child nodes -

    You can use GetNodeCount method to know if a node has children, and how many.
    GetNodeCount receives a boolean parameter, if True, it returns how many children that node has in all Treeview levels (recursive), if False, it returns how many children it has just in the next level (its direct children).
    VB Code:
    1. Dim NodeCount As Integer = TreeView1.SelectedNode.GetNodeCount(True) 'True = Recursive search
    2.         If NodeCount = 0 Then
    3.             MsgBox("No children!")
    4.         Else
    5.             MsgBox("This node has " & NodeCount.ToString() & " children")
    6.         End If
    Last edited by jcis; Mar 5th, 2006 at 05:28 AM.

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