Solved

VB.net problem dragging text into DataGridView

Posted on 2012-04-03
5
273 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
[X]
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
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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