PDA

Click to See Complete Forum and Search --> : Get an array of strings containing nodes text


Inhumanoid
Nov 21st, 1999, 02:30 PM
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

Serge
Nov 21st, 1999, 09:27 PM
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:

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
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)



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

Inhumanoid
Nov 22nd, 1999, 02:50 PM
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

Inhumanoid
Nov 22nd, 1999, 02:54 PM
Badaboom:



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

Inhumanoid
Nov 22nd, 1999, 05:47 PM
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 ??

Serge
Nov 22nd, 1999, 06:40 PM
Sure! Copy this code to Form_Activate event:


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
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)