ControlsEx Treeview get parent node?

Discussion in 'Questions (Windows Mobile)' started by RB Smissaert, Dec 16, 2008.

  1. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Is there any simple way to get the parent of a given node in the Treeview?
    Also it looks that child nodes always have the index -1. This is when I do:
    Tree.IndexOfNode(Tree.SelectedNode) So, I can't get the parent of a child with a loop as I can't get the index of the child node.

    RBS
     
  2. specci48

    specci48 Well-Known Member Licensed User

    Hello RB Smissaert,

    the index -1 indicates that currently no node is selected. You can proof this situation with the IsNull statement. E.g.:
    Code:
    If IsNull(Tree.SelectedNode) Then
        
    ' do nothing
    Else
        
    ' do something
    End If
    To get the parent node of a child node just use the parent instruction:
    Code:
    node2.Value = node1.Parent
    As above, this line of code will only run fine if the value of node1 is not null.

    And again my personal tip for the treeview ;) :
    You might have a look at my ToDoTree application which implements a lot of features around the treeview control.



    specci48
     
  3. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    > the index -1 indicates that currently no node is selected.

    Not with me. I have a node selected, but it still gives me -1.
    Will have a look again. Thanks for the tip about the Parent property, didn't
    see that in the help and will have a look at that.

    RBS
     
  4. specci48

    specci48 Well-Known Member Licensed User

    So there is likely a bug left in your implementation... :(

    Can you upload some code that shows this behaviour so we can help you finding it?


    specci48
     
  5. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    This is the code:

    Sub mnuShowTable_Click

    'will show the first 20 rows of the selected table
    '-------------------------------------------------
    Dim lNodeIndex
    Dim strTable
    Dim strSQL

    lNodeIndex = Tree.IndexOfNode(Tree.SelectedNode)

    If lNodeIndex = -1 Then
    Msgbox("You need to select the node with the table name.", _
    "showing table sample", _
    cMsgboxOK, _
    cMsgboxNone)
    Return
    End If

    strTable = Tree.SelectedText
    strSQL = "SELECT * FROM " & strTable & " limit 20"
    cmd.CommandText = strSQL
    cmd.ExecuteTable("Table1", 20)

    Form2.Close

    End Sub


    RBS
     
  6. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    I forgot to post the code that sets up the treeview:

    Sub mnuShowDB_Click

    Dim i

    For i = 0 To Tree.Count - 1
    Tree.RemoveNodeAt(0)
    Next

    Con.BeginTransaction

    strSQL = "SELECT name FROM sqlite_master WHERE type = 'table'"

    cmd.CommandText = strSQL

    Reader.Value = cmd.ExecuteReader

    Do While Reader.ReadNextRow = True
    Tree.AddNewNode(Reader.GetValue(0))
    Loop

    Reader.Close

    For i = 0 To Tree.Count - 1
    Node.Value = Tree.GetNode(i)
    cmd.CommandText = "PRAGMA table_info ('" & Node.Text & "')"
    Reader.Value = cmd.ExecuteReader
    Do While Reader.ReadNextRow = True
    Node.AddNewNode(Reader.GetValue(1) & " : " & Reader.GetValue(2))
    Loop
    Reader.Close
    Next i

    Con.EndTransaction

    Form2.Show

    End Sub


    RBS
     
  7. specci48

    specci48 Well-Known Member Licensed User

    Hi RB Smissaert,

    instead of
    Code:
    For i = 0 To Tree.Count - 1
        Tree.RemoveNodeAt(
    0)
    Next
    you can code
    Code:
    Tree.RemoveAllNodes
    And you can replace
    Code:
    Dim lNodeIndex

    lNodeIndex = Tree.IndexOfNode(Tree.SelectedNode)

    If lNodeIndex = -1 Then
        
    Msgbox("You need to select the node with the table name.", _"showingtable sample", _cMsgboxOK, _cMsgboxNone)
        
    Return
    End If
    with
    Code:
    If IsNull(Tree.SelectedNode) Then
        
    Msgbox("You need to select the node with the table name.", _"showingtable sample", _cMsgboxOK, _cMsgboxNone)
        
    Return
    End If[

    specci48
     
  8. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Thanks for the tips, but does that solve my problem, which is that I get a node index of -1 even when a node is selected?

    RBS
     
  9. specci48

    specci48 Well-Known Member Licensed User

    Where did you get your node index = -1 ?

    According to the help file IndexOfNode returns -1 if the node does not exist.
     
  10. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    When I have a child node selected and run the code I posted first.

    RBS
     
  11. Cableguy

    Cableguy Expert Licensed User

    I believe that for each "level" of childs, a new node name must be given, by adding it to the objects references...
    something like:

    root
    !-Level1
    !---|-level2
    !-Level1
    !-Level1
    ----!Level2
     
  12. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    How do you suggest I should change the code?

    RBS
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice