Solved

root node of the source treeView

Posted on 2009-05-11
7
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 86

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 86

Expert Comment

by:Mike Tomlinson
ID: 24359774
One moment please...
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 86

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

737 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