Prev: Why is the bool type 4 bytes it's a wast of memory..
Next: Operation is not valid due to the current state of the object
From: Ray Mitchell on 28 May 2010 04:46 Hello, Implementing drag & drop in C# seems pretty easy. However, in attempting to do so I ran into an issue that I don't understand. I found that I could drag & drop icons but when I tried to drag & drop text it would always display the red circle with the bar through it, so I would never even get to the point of being allowed to drop it. As first I thought it was something wrong in my code (which it may still be), but when I tried to drag & drop text between two 3rd party text editor applications like Wordpad and UltraEdit, it wouldn't let me do that either. However, I could drag text from one point to another within the same application. Do you have any idea why dragging & dropping text between different applications wouldn't work? Thanks, Ray
From: Peter Duniho on 28 May 2010 05:32 Ray Mitchell wrote: > Hello, > > Implementing drag & drop in C# seems pretty easy. However, in attempting to > do so I ran into an issue that I don't understand. I found that I could drag > & drop icons but when I tried to drag & drop text it would always display the > red circle with the bar through it, so I would never even get to the point of > being allowed to drop it. As first I thought it was something wrong in my > code (which it may still be), but when I tried to drag & drop text between > two 3rd party text editor applications like Wordpad and UltraEdit, it > wouldn't let me do that either. However, I could drag text from one point to > another within the same application. Do you have any idea why dragging & > dropping text between different applications wouldn't work? If you've looked into how drag & drop is implemented in your application, then you know that your application has to handle certain events, and in doing so has to inspect the data types available on the clipboard and decide whether it can handle those data types or not. I can't explain the specific behavior between Wordpad and UltraEdit, but presumably neither is publishing on the clipboard a data format the other recognizes. Likewise, if you want to be able to drag & drop text into your application, you need to make sure that a) the application sending the text is really putting a text format on the clipboard, and b) your application is really reporting that it can handle the text format on the clipboard, and of course c) that it actually _can_ handle the text format on the clipboard. There are multiple types of text formats (e.g. plain text and RTF), so make sure your application is able to handle the ones you care about. Without a concise-but-complete code example that reliably demonstrates the problem, it would not be possible to provide advice much more specific than the above with respect to what is actually wrong with your program. Pete
From: Ray Mitchell on 28 May 2010 12:49 "Peter Duniho" wrote: > Ray Mitchell wrote: > > Hello, > > > > Implementing drag & drop in C# seems pretty easy. However, in attempting to > > do so I ran into an issue that I don't understand. I found that I could drag > > & drop icons but when I tried to drag & drop text it would always display the > > red circle with the bar through it, so I would never even get to the point of > > being allowed to drop it. As first I thought it was something wrong in my > > code (which it may still be), but when I tried to drag & drop text between > > two 3rd party text editor applications like Wordpad and UltraEdit, it > > wouldn't let me do that either. However, I could drag text from one point to > > another within the same application. Do you have any idea why dragging & > > dropping text between different applications wouldn't work? > > If you've looked into how drag & drop is implemented in your > application, then you know that your application has to handle certain > events, and in doing so has to inspect the data types available on the > clipboard and decide whether it can handle those data types or not. > > I can't explain the specific behavior between Wordpad and UltraEdit, but > presumably neither is publishing on the clipboard a data format the > other recognizes. Likewise, if you want to be able to drag & drop text > into your application, you need to make sure that a) the application > sending the text is really putting a text format on the clipboard, and > b) your application is really reporting that it can handle the text > format on the clipboard, and of course c) that it actually _can_ handle > the text format on the clipboard. > > There are multiple types of text formats (e.g. plain text and RTF), so > make sure your application is able to handle the ones you care about. > > Without a concise-but-complete code example that reliably demonstrates > the problem, it would not be possible to provide advice much more > specific than the above with respect to what is actually wrong with your > program. > > Pete > . > Hi Pete, Yes, I have implemented the proper events in my code and I am considering the various types of things that may be dragged and dropped. However, you mention something that is probably at the root of the problem. Obviously I don't know much about the underlying mechanisms that make drag and drop work so I just assumed that if drag and drop worked withing a particular application it should also work between such applications, such as between UltraEdit and Wordpad. But you mentioned that an application might not actually use the clipboard to perform drag and drop of text, so that is probably the reason for the behavior I am seeing. So, how would such applications be doing drag and drop of text if they don't do it that way? Is there some reason that they would want to do it that way instead? Thanks, Ray
From: Peter Duniho on 28 May 2010 22:53
Ray Mitchell wrote: > [...] But you mentioned that an application might not > actually use the clipboard to perform drag and drop of text, so that is > probably the reason for the behavior I am seeing. So, how would such > applications be doing drag and drop of text if they don't do it that way? Is > there some reason that they would want to do it that way instead? An application may bypass the clipboard when doing D&D internally simply because it's more efficient. Even if it does use the clipboard, it may put some proprietary format onto the clipboard rather than one that is portable to other applications. Basically, you need to write your drag/drop target code so that you accept as many different pre-defined formats as possible (see the clipboard API for specific formats), and then hope that the other application will in fact be publishing one of those formats on the clipboard when it acts as a drag/drop source. Pete |