Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


Click here to copy the following block
' Returns a value >0 if node1 is a parent (or grandparent) of node2
' Returns a value <0 if node1 is a child (or grandchild) of node2
' in both cases the number reflects the number of levels between the two nodes
' Returns 0 if the two Nodes are the same or if they belong to different
' subtrees

Function GetNodeRelationship(ByVal node1 As TreeNode, ByVal node2 As TreeNode) _
  As Integer
  If node1 Is node2 Then
    ' this is the simplest case
    Return 0
  ElseIf node1.FullPath.Length > node2.FullPath.Length Then
    ' if the two nodes belong to the same subtree,
    ' then node1 is a (grand)child of node2
    If node1.FullPath.IndexOf(node2.FullPath) = 0 Then
      ' do the loop only if the two nodes appear to belong to the same
      ' subtree check that the relationship really exists
      Do Until (node1.Parent Is Nothing)
        node1 = node1.Parent
        GetNodeRelationship = GetNodeRelationship - 1
        If node1 Is node2 Then Exit Function
      Loop
    End If
  Else
    ' if the two nodes belong to the same subtree,
    ' then node1 is a (grand)parent of node2
    If node2.FullPath.IndexOf(node1.FullPath) = 0 Then
      ' do the loop only if the two nodes appear to belong to the same
      ' subtree check that the relationship really exists
      Do Until (node2.Parent Is Nothing)
        node2 = node2.Parent
        GetNodeRelationship = GetNodeRelationship + 1
        If node1 Is node2 Then Exit Function
      Loop
    End If
  End If

  ' Nodes belong to different subtrees
  Return 0
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.