473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 3354
"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 QueryContinueDrag? 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_DragOver(object sender, DragEventArgs e)
{
TreeNode currentNode =
treeView1.GetNodeAt(treeView1.PointToClient(MouseP osition));

if (lastNode != null && lastNode != currentNode)
{
lastNode.BackColor = SystemColors.Window;
lastNode.ForeColor = SystemColors.ControlText;
}

lastNode = currentNode;

if (currentNode == null)
e.Effect = DragDropEffects.None;
else
{
currentNode.BackColor = SystemColors.Highlight;
currentNode.ForeColor = SystemColors.HighlightText;
e.Effect = DragDropEffects.All;
}
}

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

void treeView1_DragLeave(object sender, EventArgs e)
{
if (lastNode != null)
{
lastNode.BackColor = SystemColors.Window;
lastNode.ForeColor = SystemColors.ControlText;
}

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.Continue; 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.comwrote:
>"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 QueryContinueDrag? 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_DragOver(object sender, DragEventArgs e)
{
TreeNode currentNode =
treeView1.GetNodeAt(treeView1.PointToClient(Mouse Position));

if (lastNode != null && lastNode != currentNode)
{
lastNode.BackColor = SystemColors.Window;
lastNode.ForeColor = SystemColors.ControlText;
}

lastNode = currentNode;

if (currentNode == null)
e.Effect = DragDropEffects.None;
else
{
currentNode.BackColor = SystemColors.Highlight;
currentNode.ForeColor = SystemColors.HighlightText;
e.Effect = DragDropEffects.All;
}
}

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

void treeView1_DragLeave(object sender, EventArgs e)
{
if (lastNode != null)
{
lastNode.BackColor = SystemColors.Window;
lastNode.ForeColor = SystemColors.ControlText;
}

lastNode = null;
}
Oct 23 '08 #3

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

Similar topics

2
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...
4
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...
4
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...
14
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...
1
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...
0
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...
0
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...
1
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...
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
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,...
0
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...

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.