|
-
Nov 21st, 1999, 03:30 PM
#1
Thread Starter
Hyperactive Member
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
-
Nov 21st, 1999, 10:27 PM
#2
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).]
-
Nov 22nd, 1999, 03:50 PM
#3
Thread Starter
Hyperactive Member
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
-
Nov 22nd, 1999, 03:54 PM
#4
Thread Starter
Hyperactive Member
Badaboom:
Code:
Private Sub TreeView1_GotFocus()
Dim nodX As Node
Set nodX = TreeView1.SelectedItem
Call TreeView1_NodeClick(nodX)
End Sub
-
Nov 22nd, 1999, 06:47 PM
#5
Thread Starter
Hyperactive Member
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 ??
-
Nov 22nd, 1999, 07:40 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|