Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net problem dragging text into DataGridView

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
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

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)
Avatar of Murray Brown

ASKER

Hi. That still gives System.Windows.Forms.DataObject
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
ASKER CERTIFIED SOLUTION
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks