Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Read Nodes in Treeview

Posted on 2010-08-26
12
Medium Priority
?
558 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
  • 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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 49

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 49

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 49

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

963 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