Solved

VB.net problem dragging text into DataGridView

Posted on 2012-04-03
5
270 Views
Last Modified: 2012-04-04
Hi. I am trying to drag the name of a TreeView node (shown at the bottom) into a DataGridView cell. I gather the text using oText below but I get
"System.Windows.Forms.DragEventArgs"

    Private Sub DataGridView1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop
     
Dim oText as string = e


   Private Sub TreeView_From_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles TreeView_From.DragEnter
        'See if there is a TreeNode being dragged
        If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", _
            True) Then
            'TreeNode found allow move effect
            'e.Effect = DragDropEffects.Move
            e.Effect = DragDropEffects.All

        Else
            'No TreeNode found, prevent move
            e.Effect = DragDropEffects.None
            Exit Sub
        End If
0
Comment
Question by:murbro
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37803855
try
Dim oText = e.Data

Open in new window

rather than the plain data. youcan also look at using the GetDataPresent() method (or indeed check the type of the data to extract the node name / text values)
0
 

Author Comment

by:murbro
ID: 37804846
Hi. That still gives System.Windows.Forms.DataObject
0
 

Author Comment

by:murbro
ID: 37804853
I don't understand this because in the drag I used
            DoDragDrop(e.Item.text, DragDropEffects.All)
and when I drop it into Excel it works as text
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 37804979
The DataObject is a treenode, so if you cast e.Data to a treenode, you can get the node text / name etc
0
 

Author Closing Comment

by:murbro
ID: 37805248
thanks
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

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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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