TreeView Data... 
Author Message
 TreeView Data...

Before I explain what I want to do, here is the source code I'm playing
around with from the MSDN cd's.

Private Sub Form_Load()

   Dim nodX As Node
   Set nodX = TreeView1.Nodes.Add(, , "dad", "Mike")
   Set nodX = TreeView1.Nodes.Add(, , "mom", "Carol")
   ' Alice is the LastSibling.
   Set nodX = TreeView1.Nodes.Add(, , , "Alice")

   Set nodX = TreeView1.Nodes.Add("mom", tvwChild, , "Marsha")
   Set nodX = TreeView1.Nodes.Add("mom", tvwChild, , "Jan")
   ' Cindy is the LastSibling.
   Set nodX = TreeView1.Nodes.Add("mom", tvwChild, , "Cindy")
   nodX.EnsureVisible ' Show all nodes.

   Set nodX = TreeView1.Nodes.Add("dad", tvwChild, , "Greg")
   Set nodX = TreeView1.Nodes.Add("dad", tvwChild, , "Peter")
   ' Bobby is the LastSibling.
   Set nodX = TreeView1.Nodes.Add("dad", tvwChild, , "Bobby")
   nodX.EnsureVisible ' Show all nodes.

End Sub

Private Sub TreeView1_NodeClick(ByVal Node As Node)
   Dim strText As String
   Dim n As Integer
   ' Set n to FirstSibling's index.
   n = Node.FirstSibling.Index
   ' Place FirstSibling's text & linefeed in string variable.
   strText = Node.FirstSibling.Text & vbLf
   ' While n is not the index of the last sibling, go to the
   ' next sibling and place its text into the string variable.
   While n <> Node.LastSibling.Index
      strText = strText & TreeView1.Nodes(n).Next.Text & vbLf
   ' Set n to the next node's index.
      n = TreeView1.Nodes(n).Next.Index
   Wend
   MsgBox strText ' Display results.
End Sub

-----------------End

Now, when you click on Mike, Carol, or Alice, I get thier names. What I want
is the childrens names. So if I click on Mike, I get Greg, Peter, Bobby, and
if I click on Carol, I get Marsha, Jan and Cindy and if I click on Alice, I
get nothing. I've been killing myself trying to figure this out.



Thu, 22 May 2003 03:00:00 GMT  
 TreeView Data...
Here is a start.  It is a quick modification that gives a clue as to how to
perform the task.  What is required is to set a node oblect equal to the
node.chile and then use the existing code.  Here is the modified code:

Private Sub Form_Load()

   Dim nodX As Node
   Set nodX = TreeView1.Nodes.Add(, , "dad", "Mike")
   Set nodX = TreeView1.Nodes.Add(, , "mom", "Carol")
   ' Alice is the LastSibling.
   Set nodX = TreeView1.Nodes.Add(, , , "Alice")

   Set nodX = TreeView1.Nodes.Add("mom", tvwChild, , "Marsha")
   Set nodX = TreeView1.Nodes.Add("mom", tvwChild, , "Jan")
   ' Cindy is the LastSibling.
   Set nodX = TreeView1.Nodes.Add("mom", tvwChild, , "Cindy")
   nodX.EnsureVisible ' Show all nodes.

   Set nodX = TreeView1.Nodes.Add("dad", tvwChild, , "Greg")
   Set nodX = TreeView1.Nodes.Add("dad", tvwChild, , "Peter")
   ' Bobby is the LastSibling.
   Set nodX = TreeView1.Nodes.Add("dad", tvwChild, , "Bobby")
   nodX.EnsureVisible ' Show all nodes.

End Sub

Private Sub TreeView1_NodeClick(ByVal Node As Node)
   Dim strText As String
   Dim n As Integer
   Dim xNode As Node
   ' Set n to FirstSibling's index.
   Set xNode = Node.Child
   If Not xNode Is Nothing Then
        n = xNode.FirstSibling.Index
        ' Place FirstSibling's text & linefeed in string variable.
        strText = xNode.FirstSibling.Text & vbLf
        ' While n is not the index of the last sibling, go to the
        ' next sibling and place its text into the string variable.
        While n <> xNode.LastSibling.Index
           strText = strText & TreeView1.Nodes(n).Next.Text & vbLf
        ' Set n to the next node's index.
           n = TreeView1.Nodes(n).Next.Index
        Wend
    End If
   If strText <> "" Then MsgBox strText ' Display results.
End Sub

Good luck!

Al Reid


Quote:
> Before I explain what I want to do, here is the source code I'm playing
> around with from the MSDN cd's.

> Private Sub Form_Load()

>    Dim nodX As Node
>    Set nodX = TreeView1.Nodes.Add(, , "dad", "Mike")
>    Set nodX = TreeView1.Nodes.Add(, , "mom", "Carol")
>    ' Alice is the LastSibling.
>    Set nodX = TreeView1.Nodes.Add(, , , "Alice")

>    Set nodX = TreeView1.Nodes.Add("mom", tvwChild, , "Marsha")
>    Set nodX = TreeView1.Nodes.Add("mom", tvwChild, , "Jan")
>    ' Cindy is the LastSibling.
>    Set nodX = TreeView1.Nodes.Add("mom", tvwChild, , "Cindy")
>    nodX.EnsureVisible ' Show all nodes.

>    Set nodX = TreeView1.Nodes.Add("dad", tvwChild, , "Greg")
>    Set nodX = TreeView1.Nodes.Add("dad", tvwChild, , "Peter")
>    ' Bobby is the LastSibling.
>    Set nodX = TreeView1.Nodes.Add("dad", tvwChild, , "Bobby")
>    nodX.EnsureVisible ' Show all nodes.

> End Sub

> Private Sub TreeView1_NodeClick(ByVal Node As Node)
>    Dim strText As String
>    Dim n As Integer
>    ' Set n to FirstSibling's index.
>    n = Node.FirstSibling.Index
>    ' Place FirstSibling's text & linefeed in string variable.
>    strText = Node.FirstSibling.Text & vbLf
>    ' While n is not the index of the last sibling, go to the
>    ' next sibling and place its text into the string variable.
>    While n <> Node.LastSibling.Index
>       strText = strText & TreeView1.Nodes(n).Next.Text & vbLf
>    ' Set n to the next node's index.
>       n = TreeView1.Nodes(n).Next.Index
>    Wend
>    MsgBox strText ' Display results.
> End Sub

> -----------------End

> Now, when you click on Mike, Carol, or Alice, I get thier names. What I
want
> is the childrens names. So if I click on Mike, I get Greg, Peter, Bobby,
and
> if I click on Carol, I get Marsha, Jan and Cindy and if I click on Alice,
I
> get nothing. I've been killing myself trying to figure this out.



Fri, 23 May 2003 09:56:17 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. TreeView data object

2. TreeView data object

3. TreeView data object

4. Dynamic Treeview Data Loading

5. Data Binding and TreeView

6. Loading treeview with Data

7. Using Treeview to display columns of data?

8. TreeView - Hierarchical Data from Flat Table

9. Populating Treeview with data from Dataset

10. Store XML data into TreeView

11. showing field data from a table using a treeview control

12. Associating data with a node in a treeview

 

 
Powered by phpBB® Forum Software