Solved

root node of the source treeView

Posted on 2009-05-11
7
247 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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