Solved

VB.net problem dragging text into DataGridView

Posted on 2012-04-03
5
267 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
Comment Utility
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
Comment Utility
Hi. That still gives System.Windows.Forms.DataObject
0
 

Author Comment

by:murbro
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

10 Experts available now in Live!

Get 1:1 Help Now