tidydave
asked on
Adding a FullPath method to the TreeNode object of the TreeView object
Dear Fellow Human,
I am creating a TreeView that is linked to the filesystem.
I am using ASP.NET and the Treeview object. I created an expand event that passed through e As TreeViewClickEventArgs.
I can inspect e.Node to get the "nodeIndex" i.e. "0.0.0" etc.
I can also
Dim expandNode As TreeNode
expandNode = Tree.GetNodeFromIndex(e.No de)
In VB.NET (Windows Forms), the TreeNode object has a "FullPath" method.
In ASP.NET (Web Forms), the TreeNode object does not have this method.
So I had to write a Function to take a nodeIndex e.g. "0.0.0" and convert it to the FullPath. This wasn't very elegant.
Dim FullPath As String
FullPath = TreeNodePath(expandNode.Ge tNodeIndex )
Here is the function, skip past this for more information.
Function TreeNodePath(ByVal nodeIndex As String) As String
Dim i As Integer
Dim fullPath, currentIndex As String
Dim indexArray As Array
' split the nodeIndex path, usually nodeIndexes are of the form 0.1.0 or 0.2.1
indexArray = nodeIndex.Split(".")
For i = 0 To indexArray.GetUpperBound(0 )
If i = 0 Then
' this will be the root node
currentIndex = indexArray(i)
Else
currentIndex += "." & indexArray(i)
End If
If i = indexArray.GetUpperBound(0 ) Then
' last node so don't have to add a "\"
fullPath += Tree.GetNodeFromIndex(curr entIndex). Text
Else
fullPath += Tree.GetNodeFromIndex(curr entIndex). Text & "\"
End If
Next
Return fullPath
End Function
What I would like to do... is somehow add the TreeNodePath function to the TreeNode object of the TreeView object. I would probably rename it to "FullPath" to keep it in line with the VB.NET TreeNode object (Windows Forms).
I know that the new version of the TreeView object in ASP 2.0, will most likely have this method available in the TreeNode Object.
However, I want to improve my coding skills, and understand how I could merge extra methods into existing objects.
Is this possible?
Kind Regards,
Dave Kirkby
<email removed by mmarinov .NET Topic Area Page Editor>
I am creating a TreeView that is linked to the filesystem.
I am using ASP.NET and the Treeview object. I created an expand event that passed through e As TreeViewClickEventArgs.
I can inspect e.Node to get the "nodeIndex" i.e. "0.0.0" etc.
I can also
Dim expandNode As TreeNode
expandNode = Tree.GetNodeFromIndex(e.No
In VB.NET (Windows Forms), the TreeNode object has a "FullPath" method.
In ASP.NET (Web Forms), the TreeNode object does not have this method.
So I had to write a Function to take a nodeIndex e.g. "0.0.0" and convert it to the FullPath. This wasn't very elegant.
Dim FullPath As String
FullPath = TreeNodePath(expandNode.Ge
Here is the function, skip past this for more information.
Function TreeNodePath(ByVal nodeIndex As String) As String
Dim i As Integer
Dim fullPath, currentIndex As String
Dim indexArray As Array
' split the nodeIndex path, usually nodeIndexes are of the form 0.1.0 or 0.2.1
indexArray = nodeIndex.Split(".")
For i = 0 To indexArray.GetUpperBound(0
If i = 0 Then
' this will be the root node
currentIndex = indexArray(i)
Else
currentIndex += "." & indexArray(i)
End If
If i = indexArray.GetUpperBound(0
' last node so don't have to add a "\"
fullPath += Tree.GetNodeFromIndex(curr
Else
fullPath += Tree.GetNodeFromIndex(curr
End If
Next
Return fullPath
End Function
What I would like to do... is somehow add the TreeNodePath function to the TreeNode object of the TreeView object. I would probably rename it to "FullPath" to keep it in line with the VB.NET TreeNode object (Windows Forms).
I know that the new version of the TreeView object in ASP 2.0, will most likely have this method available in the TreeNode Object.
However, I want to improve my coding skills, and understand how I could merge extra methods into existing objects.
Is this possible?
Kind Regards,
Dave Kirkby
<email removed by mmarinov .NET Topic Area Page Editor>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.