Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Read Nodes in Treeview

Posted on 2010-08-26
12
Medium Priority
?
548 Views
Last Modified: 2012-06-22
I have three levels of nodes.  I can get the value of the current node.  How do I get the value of the node above it?  Thanks.
0
Comment
Question by:Sasha42
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 2

Expert Comment

by:SkydiverFL
ID: 33533261
If this is .NET, you should be able to get node.Parent to find the parent node.  As for the "value" it depends on what you want.  If you have stored something in the Tag, just look at node.Parent.Tag or node.Tag.  If you are looking for the text (most common), just grab node.Text or node.Parent.Text.  Remember, a TreeNode is a DISPLAY element so they do not contain a value per se.
0
 
LVL 75
ID: 33533738
Mike ... check this out:

  http://datapigtechnologies.com/AccessMain.htm

(Scroll down to bottom until you get to Access Tools)

Full mdb examples and online video tutorial ... it's a great jump start.

mx
0
 
LVL 75
ID: 33533743
More:

Here are step by step Treeview instruction with source code and references
           http://www.databasejournal.com/features/msaccess/article.php/3734331/Access-TreeView-ListView-Basics.htm

http://support.microsoft.com/kb/209891/en-us
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:Dale Fye
ID: 33534758
Technically, nodes don't have values.  Are you trying to determine the key or the text associated with a nodes parent?  What event are you using?  If you are using an event that already displays the node object (like Collapse, Expand, NodeClick, ...) then you can use something like:

    node.parent.key



0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 33534778

However, that will raise an error if the node is in your upper most level.  I usually set the Tag property of the node to the level as I create them, this way I can use that property to determine what level of the tree the node is at.

    if node.tag <> 1 Then
        debug.print node.parent.key
    end if
0
 

Author Comment

by:Sasha42
ID: 33535038
Below is the code that builds the tree.  I have code that when I double click on John Doe it returns the text - Set CurNode = Me!axTreeView.SelectedItem.  What i need is the CaseNumber (parent) so that I can open a form with the CaseNumer and the Person's Name.  Thanks.

The tree looks this:
CaseNumber123
CaseNumber456
  +Witness
        John Doe
+Victim
        Moe Stooge

sSQL = "select * from tblcases"
     
    Set rs = db.OpenRecordset(sSQL, dbOpenForwardOnly)
   
     Do Until rs.EOF
        Me!axTreeView.Nodes.Add , , rs!AllegationNumber, rs!AllegationNumber
        rs.MoveNext
    Loop
    rs.Close
   
     'Fill Level 2.
    Set rs = db.OpenRecordset("qryAssociationCategory1", dbOpenForwardOnly)
    Do Until rs.EOF
        strOrderKey = StrConv("o" & rs!AssociationCatagory, vbLowerCase)
        Me!axTreeView.Nodes.Add rs!AllegationNumber.Value, tvwChild, strOrderKey, _
           rs!AssociationCatagory
        rs.MoveNext
    Loop
    rs.Close
   
    ' Fill Level 3.
 Set rs = db.OpenRecordset("qryAssociationCategory2", dbOpenForwardOnly)
    Set rs = db.OpenRecordset("tblActivities", dbOpenForwardOnly)
    Do Until rs.EOF
        strOrderKey = StrConv("o" & rs!AssociationCatagory, vbLowerCase)
        strProductKey = StrConv(strOrderKey & "p" & rs!PersonID, vbLowerCase)
        Me!axTreeView.Nodes.Add strOrderKey, tvwChild, strProductKey, _
           rs!PersonProviderName
        rs.MoveNext
    Loop
    rs.Close
0
 
LVL 2

Expert Comment

by:SkydiverFL
ID: 33535264
The challenge that you are going to have is knowing exactly WHAT you are selecting.  Based on your explanation, and the code provided, the user can click on ANY node... Case, Witness, Person, etc.  You're gonna have to walk the tree back upward to find the case.

For example:

TreeNode curNode = selectedNode;
while ( curNode.Parent != null )
{
     curNode = curNode.Parent;
}

This will give you the top-most parent... the case.  Then, just evaluate the final curNode for the value you want.
0
 
LVL 2

Expert Comment

by:SkydiverFL
ID: 33535295
Expanded example...

public TreeNode getRoot ( TreeNode node )
{
     if ( node == null ){ return null; } // Nothing was supplied ... gracefully exit.
     if ( node.Parent == null ){ return node; }  // Supplied node is the root.

     TreeNode curNode = selectedNode;
     while ( curNode.Parent != null )
     {
          curNode = curNode.Parent;
     }
     
     return curNode;
}
0
 

Author Comment

by:Sasha42
ID: 33535322
Thanks!! Sorry, I don't understand the code you wrote.  What is { ?  
0
 
LVL 2

Expert Comment

by:SkydiverFL
ID: 33535573
Sorry... it was C#.  The equivalent VB should be...

    Function getNode(ByVal node As TreeNode) As TreeNode
        If node Is Nothing Then Return Nothing
        If node.Parent Is Nothing Then Return Nothing

        Dim curNode As TreeNode
        curNode = Nothing
        Do While curNode.Parent IsNot Nothing
            curNode = curNode.Parent
        Loop

        Return curNode
    End Function
0
 

Author Comment

by:Sasha42
ID: 33535966
Thanks again.  I cannot get it to work in VBA.  I have tried several variations.  
0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 33537725
Instead of using the doubleclick event, use the NodeClick event.  Try:

Private Sub axTreeView_NodeClick(ByVal Node as Object)

    Dim nd as MSComctlLib.Node

    set nd = Node
    while not nd.Parent is nothing
        set nd = nd.Parent
    Wend

    debug.print nd.key, nd.text
    docmd.openform "YourFormName",, , "[AllegationNumber] = '" & nd.key & "'"

End Sub

This assumes that AllegationNumber is actually a string, since key values must be strings.






0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question