Solved

root node of the source treeView

Posted on 2009-05-11
7
241 Views
Last Modified: 2012-05-06
I am doing dragdrop operation from one tree to other for getting source node i am using
newNode = DirectCast(e.Data.GetData("System.Windows.Forms.TreeNode"), TreeNode)
but its only giving me node text and name

I also want to get root node of the source tree. how i can do this

Thanks
0
Comment
Question by:farjack1
  • 3
  • 3
7 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24359659
To get the root node you could do something like:

        Dim rootNode As TreeNode = newNode
        While Not IsNothing(rootNode.Parent)
            rootNode = rootNode.Parent
        End While

0
 

Author Comment

by:farjack1
ID: 24359764
rootNode.Parent

this returning Nothing
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24359774
One moment please...
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24359877
It's working fine for me...I setup two TreeViews (TreeView1, TreeView2) on a Form and added some Nodes to TreeView1.

Here is some of my Debug output:

    Dropped Node: Node7
    Root Node: Node2
    FullPath: Node2\Node7

    Dropped Node: Node14
    Root Node: Node1
    FullPath: Node1\Node6\Node14

And here is the code:
Public Class Form1
 
    Private Sub TreeView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Dim SourceNode As TreeNode = TreeView1.GetNodeAt(TreeView1.PointToClient(Cursor.Position))
            If Not IsNothing(SourceNode) Then
                TreeView1.DoDragDrop(SourceNode, DragDropEffects.All)
            End If
        End If
    End Sub
 
    Private Sub TreeView2_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView2.DragOver
        e.Effect = If(e.Data.GetDataPresent("System.Windows.Forms.TreeNode"), DragDropEffects.All, DragDropEffects.None)
    End Sub
 
    Private Sub TreeView2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView2.DragDrop
        Dim DroppedNode As TreeNode = e.Data.GetData("System.Windows.Forms.TreeNode")
        Debug.Print("Dropped Node: " & DroppedNode.Text)
 
        Dim RootNode As TreeNode = DroppedNode
        While Not IsNothing(rootNode.Parent)
            rootNode = rootNode.Parent
        End While
        If Not (rootNode Is DroppedNode) Then
            Debug.Print("Root Node: " & rootNode.Text)
        End If
 
        Debug.Print("FullPath: " & DroppedNode.FullPath)
    End Sub
 
End Class

Open in new window

0
 

Expert Comment

by:praveenkumar_3i
ID: 24362164
Try to get Parent node of a xml documnet.

Code Sample:

                            XmlDocument xmldoc = new XmlDocument();
                            xmldoc.Load(strXMLFile);
                            XmlNode xmlRootNode = xmldoc.ParentNode;

0
 

Expert Comment

by:praveenkumar_3i
ID: 24362184
In Treeview

TreeNodeCollection nodes = tvwFolders.Nodes;
if (nodes.Count > 0)
{
// Select the root node
tvwFolders.SelectedNode = nodes[0];
}


0
 

Accepted Solution

by:
praveenkumar_3i earned 500 total points
ID: 24362191
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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