Solved

Adding a FullPath method to the TreeNode object of the TreeView object

Posted on 2004-09-18
4
1,449 Views
Last Modified: 2008-02-01
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.Node)

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.GetNodeIndex)

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(currentIndex).Text
            Else
                fullPath += Tree.GetNodeFromIndex(currentIndex).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>
0
Comment
Question by:tidydave
4 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 500 total points
ID: 12097205
Hi tidydave,

You have to create your server control, that inherits the Treeview control as a base an improve it
then you can add your method, and from this moment you can use the new created control, and not the original one

B..M
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now