Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Entire Node Path from Database without using Treeview

Status
Not open for further replies.

sam4help

Programmer
Jul 22, 2011
74
AE
Dear Experts; I have a table for the data storing of treeview.
Now, the challenge is I need to get the full path of a node without using treeview; how to achieve this I am bit confused,
any help will be highly appreciated.

So, lets say I pass a node name and function returns me entire path eg.; Attached.

2hmkoqu.png


Input Value & Result Value are color coded for easy understanding,

Best Regards,

Sam
 
You need to build a recursive function. If I get time I will try to write it, because recursive functions always kick my butt. When you say table is it and ADO.Net dataTable? This is very rough pseudo code but the general ID is there. The function keeps calling itself passing in the current node, finding its parent node, concatenating the path until it no longer finds a parent. Then it exits out.
Code:
Public function GetNodePath(Dt as DataTable, CurrentID As Variant, CurrentPath as string) as string
  dim NodeName as string
  dim strReturn as string
  Do 
    nodeName = get the currentNode Name (currentID)
    currentID = get the parent id (currentID)
    strReturn = NodeName & "/" & CurrentPath
    GetNodePath(DT, currentID, strReturn)
   Loop until not parent ID found
   Return strReturn
   Exit function
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top