Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OLE DragDrop - Drops onto It's Self!

Posted on 2000-05-08
9
Medium Priority
?
151 Views
Last Modified: 2010-05-02
How can I keep the following routine from dropping it's own selected text
onto itself?  It's a Rich Text Box. When I select some text and drag the mouse it shows that it's dragging it.  Then when I release the mouse
button it drops it on itself and deletes everything but the selected text!

It's supposed to just be able to drag-n-drop from other apps (and vice versa). How can I say:

IF Source = YourOwnDamnSelf AND Target = YourOwnDamnSelf  then
     Exit Sub
End IF

Private Sub rtbCodeWindow_OLEDragDrop(Data As RichTextLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
   
    If Data.GetFormat(vbCFText) Then  'if text
       
        If (Effect And vbDropEffectCopy) Then
            rtbCodeWindow.TextRTF = Data.GetData(vbCFText) 'set the window to the dragged in text
        Else
            rtbCodeWindow.LoadFile Data.GetData(vbCFText)  'open the dragged in file
        End If
   
    End If
   
       If Data.GetFormat(vbCFFiles) Then        'if files from explorer
        rtbCodeWindow.LoadFile Data.Files(1) 'open the file dragged from windows
    End If
   
End Sub
0
Comment
Question by:jgore
[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
  • 6
  • 3
9 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2790126
is there ever a time you actually want anything to be dropped into the rtb?  if not then set its oledropmode to rtfoledropnone
0
 

Author Comment

by:jgore
ID: 2790213
Yes! I want to be able to drag files to it!
There are lots of times I want to drag stuff over to
it. I certainly don't want to turn DragDrop off!

0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2790254
how bout just setting its .Locked property to true at the beginning of the drag event and false when its done, i.e. in the olecompletedrag event
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:jgore
ID: 2790308
I think thats just going to effect the edit-ability
of the Rich Text Box.

..Locked :
True -  You can scroll and highlight the text in the control, but you can't edit it. The program can still modify the text by changing the Text property.
False - (Default) You can edit the text in the control.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2790407
i just used your code and it didnt do what you say its doing to you...when i selected text from the rtb and dropped it back into the rtb, nothing happened.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2790415
oh never mind i had to set my drop mode to manual
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 200 total points
ID: 2790419
but the locked thing worked for me, adding these two pieces of code:


Private Sub RichTextBox1_OLECompleteDrag(Effect As Long)
    RichTextBox1.Locked = False
End Sub



Private Sub RichTextBox1_OLEStartDrag(Data As RichTextLib.DataObject, AllowedEffects As Long)
    RichTextBox1.Locked = True
End Sub


0
 

Author Comment

by:jgore
ID: 2790451
Hmmm...It does work. Very nice! THANKS!
I wonder why it works? heh. VB says it just locks editing. It also says that using the text property
should still work.

rtbCodeWindow.TextRTF = Data.GetData(vbCFText)  

Should still work. I guess I'm just reading it
wrong! I tried dragging and dropping different
stuff and it all still worked but now it won't drop
to itself, thank god! It was a real editing nightmare the other way! Thanks again!
Cya'z.................Jerry
 
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2790459
i think it would still change if you had a command button and said rtb.text = "text" but since its locked, part of what it blocks is the ability to drop items onto it, thus it will never get to your code that sets the text programmatically. well for whatever reason, glad its working for ya.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

604 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