Results 1 to 6 of 6

Thread: Get an array of strings containing nodes text

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    Post

    I want to have an array of strings that will always contain the text's of the children of the selected Node. If no node is selected the array should contain the text's of the root nodes....

    hlp....

    cheers

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    It's not a problem to do what you want except one thing. Once you select one node in a TreeView, you cannot have "No Nodes Selected", because some node will always be selected. So, my suggestion will be is to create a Root Node. Any way here is the code for the array. First you would have to create a variable (array) on general declaration of the Form. Then use this code on Node_Click event.

    Complete Code:
    Code:
    Option Explicit
    
    Private m_arrNodes() As String
    
    
    Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
        Dim iIndex As Integer
        Dim i As Integer
        
        
        ReDim m_arrNodes(i)
        If Node.Children Then
            m_arrNodes(i) = Node.Child.Text
            iIndex = Node.Child.FirstSibling.Index
            Do Until iIndex > Node.Child.LastSibling.Index
                If iIndex <> TreeView1.Nodes(iIndex).LastSibling.Index Then
                    i = i + 1
                    ReDim Preserve m_arrNodes(i)
                    m_arrNodes(i) = TreeView1.Nodes(iIndex).Next.Text
                    iIndex = TreeView1.Nodes(iIndex).Next.Index
                Else
                    iIndex = iIndex + 1
                End If
            Loop
        End If
    End Sub

    arrNodes will have Children of the currently selected node.
    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819



    [This message has been edited by Serge (edited 11-22-1999).]

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    Post

    Kewl....

    How could I port this to the trieview1_gotfocus
    event?

    I mean execute your code for the selected node as soon as the treeview gets the focus

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    Post

    Badaboom:

    Code:
    Private Sub TreeView1_GotFocus()
       Dim nodX As Node
       Set nodX = TreeView1.SelectedItem
    Call TreeView1_NodeClick(nodX)
    End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    Post

    Ok, I want m_arrnodes to fill itself with all the root nodes.. This should only happen when the program is loaded. So that the NodeClick code can take over as soon as the user starts working with the treeview..

    How can I fill the array with the text's of the root Nodes ??

  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Sure! Copy this code to Form_Activate event:

    Code:
    Private Sub Form_Activate()
        Dim iIndex As Integer
        Dim i As Integer
        
        ReDim m_arrNodes(iIndex)
        
        For i = 1 To TreeView1.Nodes.Count
            If TreeView1.Nodes(i).Parent Is Nothing Then
                ReDim Preserve m_arrNodes(iIndex)
                m_arrNodes(iIndex) = TreeView1.Nodes(i)
                iIndex = iIndex + 1
            End If
        Next
    End Sub
    m_arrNodes now holds Root Nodes Text.

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


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