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
Solved

Get TreeView node's name during drag and drop

Posted on 2012-04-02
6
410 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
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.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

789 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