Solved

Get TreeView node's name during drag and drop

Posted on 2012-04-02
6
406 Views
Last Modified: 2012-04-02
Hi. I have managed to work out how to get the node's index during drag and drop but how do I change the following code to get the node's name

    Private Sub TreeView_From_ItemDrag(sender As Object, e As System.Windows.Forms.ItemDragEventArgs) Handles TreeView_From.ItemDrag
        'Set the drag node and initiate the DragDrop
        DoDragDrop(e.Item, DragDropEffects.Copy)
        MsgBox(e.Item(e.Item.Index).name)

    End Sub
0
Comment
Question by:murbro
  • 3
  • 3
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37795039
Have you tried

MsgBox(e.Item.name)

?
0
 

Author Comment

by:murbro
ID: 37795526
Hi. That returns the word "Column" for every node. The nodes are loaded with SQL table columns. Not sure if this has something to do with it
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37795554
Show the code you use to populate the nodes.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:murbro
ID: 37795612
Public Sub Populate_TreeView_From_SQL()

        Dim SQLExpression As String = _
            "SELECT TABLE_NAME, COLUMN_NAME FROM information_schema.columns ORDER BY TABLE_NAME,COLUMN_NAME"



        Dim Rootnode As TreeNode = Nothing
        Dim Mainnode As TreeNode = Nothing
        Dim Childnode As TreeNode = Nothing

        Dim MainName As String = String.Empty

        Dim oConnectionString As String = Me.RichTextBox1.Text
        Dim cn As New SqlConnection(oConnectionString)

        Dim adp As New SqlDataAdapter(SQLExpression, cn)

        Dim ds As New DataSet

        adp.Fill(ds, "SystemData")

        Me.TreeView_From.Nodes.Clear()

        Rootnode = Me.TreeView_From.Nodes.Add(key:="Root", text:="database name here", _
                                        imageIndex:=0, selectedImageIndex:=0)



        For Each row As DataRow In ds.Tables("SystemData").Rows

            If MainName <> row(0).ToString Then
                Mainnode = Rootnode.Nodes.Add(key:="Table", text:=row(0).ToString, _
                imageIndex:=1, selectedImageIndex:=1)
                MainName = row(0).ToString
            End If

            Childnode = Mainnode.Nodes.Add(key:="Column", text:=row(1).ToString, _
            imageIndex:=2, selectedImageIndex:=2)

        Next

        Me.TreeView_From.Nodes(0).EnsureVisible()
        Me.TreeView_From.ExpandAll()
        Me.TreeView_From.Scrollable = True

        ds.Dispose()
        ds = Nothing
        adp.Dispose()
        adp = Nothing
        cn.Dispose()
        cn = Nothing

    End Sub
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37795719
>Childnode = Mainnode.Nodes.Add(key:="Column"

It appears that key is being used for name.

Try changing it to

Childnode = Mainnode.Nodes.Add(row(1).ToString)
0
 

Author Closing Comment

by:murbro
ID: 37796784
Thanks very much
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

13 Experts available now in Live!

Get 1:1 Help Now