473,770 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drag Drop out of bounds

bob
Hi all,
I have a treeview that has drag drop.
Works well enough but...
If you drag out of bounds of the treeview the nodrop icon comes on.
Fair enough.
But when I move back inside the treeview the nodrop icon stays on and
essentially the action is cancelled when I release the mouse.
I would like to somehow 'retrieve' the drag action when the mouse
moves back inside the treeview to a legitimate drop point.
Any thoughts on how to do this would be appreciated.
thanks
Bob
Oct 22 '08 #1
2 3372
"bob" wrote:
Hi all,
I have a treeview that has drag drop.
Works well enough but...
If you drag out of bounds of the treeview the nodrop icon comes on.
Fair enough.
But when I move back inside the treeview the nodrop icon stays on and
essentially the action is cancelled when I release the mouse.
I would like to somehow 'retrieve' the drag action when the mouse
moves back inside the treeview to a legitimate drop point.
Any thoughts on how to do this would be appreciated.
thanks
Bob
Hi Bob,

Are you in any way using QueryContinueDr ag? The icons pretty much sort
themselves out with minimum calculation. If you only want to allow drop on
existing TreeNodes you can use the code below as a comparison, which
highlights the current node as well. The code does not filter data types or
effects in any way.

TreeNode lastNode = null;

void treeView1_DragO ver(object sender, DragEventArgs e)
{
TreeNode currentNode =
treeView1.GetNo deAt(treeView1. PointToClient(M ousePosition));

if (lastNode != null && lastNode != currentNode)
{
lastNode.BackCo lor = SystemColors.Wi ndow;
lastNode.ForeCo lor = SystemColors.Co ntrolText;
}

lastNode = currentNode;

if (currentNode == null)
e.Effect = DragDropEffects .None;
else
{
currentNode.Bac kColor = SystemColors.Hi ghlight;
currentNode.For eColor = SystemColors.Hi ghlightText;
e.Effect = DragDropEffects .All;
}
}

void treeView1_DragE nter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects .All;
}

void treeView1_DragL eave(object sender, EventArgs e)
{
if (lastNode != null)
{
lastNode.BackCo lor = SystemColors.Wi ndow;
lastNode.ForeCo lor = SystemColors.Co ntrolText;
}

lastNode = null;
}
--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 23 '08 #2
bob
Hi Morten,
Thanks for your reply.
I realise I didn't give you the full story.
It is a scrollable treeview.
If the user is careful and just mouses up to the top or bottom edge of
the treeview. All is well it scroll and you can drop at the
appropriate place. If they barge over the treeview boundary then the
forbidden Icon appears. I want it to disappear when they come back in
bounds and allow them to continue on with the drag drop.
Thanks for the tip on using the QueryContinue drop event.
I put e.Action = DragAction.Cont inue; in the event handler but it
still insists on abandoning the dragDrop once you cross the border.
regards
Bob
On Wed, 22 Oct 2008 23:13:00 -0700, Morten Wennevik [C# MVP]
<Mo************ @hotmail.comwro te:
>"bob" wrote:
>Hi all,
I have a treeview that has drag drop.
Works well enough but...
If you drag out of bounds of the treeview the nodrop icon comes on.
Fair enough.
But when I move back inside the treeview the nodrop icon stays on and
essentially the action is cancelled when I release the mouse.
I would like to somehow 'retrieve' the drag action when the mouse
moves back inside the treeview to a legitimate drop point.
Any thoughts on how to do this would be appreciated.
thanks
Bob

Hi Bob,

Are you in any way using QueryContinueDr ag? The icons pretty much sort
themselves out with minimum calculation. If you only want to allow drop on
existing TreeNodes you can use the code below as a comparison, which
highlights the current node as well. The code does not filter data types or
effects in any way.

TreeNode lastNode = null;

void treeView1_DragO ver(object sender, DragEventArgs e)
{
TreeNode currentNode =
treeView1.GetN odeAt(treeView1 .PointToClient( MousePosition)) ;

if (lastNode != null && lastNode != currentNode)
{
lastNode.BackCo lor = SystemColors.Wi ndow;
lastNode.ForeCo lor = SystemColors.Co ntrolText;
}

lastNode = currentNode;

if (currentNode == null)
e.Effect = DragDropEffects .None;
else
{
currentNode.Bac kColor = SystemColors.Hi ghlight;
currentNode.For eColor = SystemColors.Hi ghlightText;
e.Effect = DragDropEffects .All;
}
}

void treeView1_DragE nter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects .All;
}

void treeView1_DragL eave(object sender, EventArgs e)
{
if (lastNode != null)
{
lastNode.BackCo lor = SystemColors.Wi ndow;
lastNode.ForeCo lor = SystemColors.Co ntrolText;
}

lastNode = null;
}
Oct 23 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4335
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put there? What about Drag/Drop; is there more than one way for the source to make data available Is it always OLE?
4
7272
by: zav | last post by:
Hi all i`m having a small problem with windows forms, i`m attempting to provide the following functionality to a form. Ability to drag and drop another form onto a form and then to dock this form... Quite a mouthful however a good example of this is within the VS.NET 6 IDE. Grab your solution explorer panel and drop it outside of the IDE, then drag/drop it back in and watch it dock.
4
2212
by: Qingdong Z. | last post by:
I have a VS.NET windows application which use drag-drop feather. It works fine when application start, but stops working after application run one or two days. The application is related to Video process, CPU/Memory extensive. The drag-drop is in a new windows form. It drags from TreeView Control to other control in the same form. It cannot trigger ItemDrag event of TreeView after drag-drop feather die. Can you give me any idea? Thanks.
14
2177
by: Nathan | last post by:
I'm working for the first time with the DoDragDrop method. I've got almost everything worked out, but I need some help with the last bit. There are two listboxes on my form, lstGroups and lstStudents. I want to be able to drag a name from lstStudents and drop it on one of the names in lstGroups to move it to that group. I've got the dragging part working; it's just the dropping that isn't there yet. I'm working with what I can find...
1
1620
by: Kevin L | last post by:
I have a Panel control that I currently allow the user to drag and reposition on a form at runtime. This Panel control contains a Label control. I would like to allow the user to drag the PANEL by clicking on the LABEL and dragging. Is there a way to do this?
0
1268
by: SamSpade | last post by:
I've mentioned in other post that I've implemented Drag/Drop for a RichTextBox and using it clears the undo buffer except for the Drag/Drop undo. I'd love to hear from someone that they have experienced the same thing or that their implementation does not clear the buffer. Now for the reason for this post: I've noticed in the documentation that there is a OLE Drag/Drop.
0
1779
by: Pesso | last post by:
I'm loading a text file to a RichTextBox control to drag a selection of a text and drop it into a tree view control. It works except after the drag and drop operation the RichTextBox scrolls to the top. This is very inconvenient because after the drag-drop operation the user has to scroll down to where he was before. Is there anyway to make the RichTextBox stop jumping to the top after a drag-drop from it?
1
5015
by: timnels | last post by:
I have created a muti-select treeview control. Problem is I am now trying to implement drag/drop in the application that uses it. It seems the mouse down and mouse move events fire before the OnBeforeSelect and OnAfterSelect events in the treeview. Since I want to start the drag/drop on the mouse move event, I have no clue that the current node has been selected yet. I tried moving all the code into the mouse down event (which actually...
4
3653
by: Jeff | last post by:
Hello, I am trying to drag and drop a label control from one cell in a tablelayoutpanel to another (VB2005). There is no problem if both cells are visible, but i cannot get the tablelayoutpanel to scroll in any direction (autoscroll is on), when the cell i want to drag to is no currently visible and requires scrolling to get to see it. Any suggestions would be greatly appreciated.
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.