?
Solved

root node of the source treeView

Posted on 2009-05-11
7
Medium Priority
?
250 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1500 total points
ID: 24362191
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 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