Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net drag and drop into RichTextBox

Posted on 2012-04-09
2
Medium Priority
?
1,337 Views
Last Modified: 2012-04-09
Hi. I was given code to drag and drop from a ListBox into a TextBox asnd it worked well.
I also need to be able to drop into a RichTextBox. The following code doesn't achieve that.
I set AllowDrop = True in the form load event.


    Private Sub ListBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
        ' Drag and Drop STEP 1
        If e.Button = Windows.Forms.MouseButtons.Left AndAlso Me.ListBox1.SelectedItem IsNot Nothing Then
            Me.ListBox1.DoDragDrop(Me.ListBox1.SelectedItem.ToString(), DragDropEffects.Copy)
        End If

    End Sub

    Private Sub RichTextBox1_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
        ' Drag and Drop STEP 2
        If e.Data.GetDataPresent(System.Windows.Forms.DataFormats.StringFormat) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub


    Private Sub RichTextBox1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
        ' Drag and Drop STEP 3
        If e.Data.GetDataPresent(System.Windows.Forms.DataFormats.StringFormat) Then
            Me.RichTextBox1.Text = e.Data.GetData(System.Windows.Forms.DataFormats.StringFormat).ToString()
        End If
    End Sub
0
Comment
Question by:Murray Brown
[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
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 37823069
DragEnter doesn't seem to function in the same way for RTB as it does for TB. I switched to DragOver, and it appears to work.

Private Sub RichTextBox1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragOver
    ' Drag and Drop STEP 2
    If e.Data.GetDataPresent(System.Windows.Forms.DataFormats.StringFormat) Then
        e.Effect = DragDropEffects.Copy
    End If
End Sub

Open in new window

0
 

Author Closing Comment

by:Murray Brown
ID: 37823085
Thanks very much
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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 …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

660 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