TreeViews

D

Dom

I'm using a TreeView and I want the user to drag and drop the nodes to
change the look of the tree, just like we change file-locations in "My
Computer". I do the following:

1. Capture MouseDown and start DoDragDrop.
2. Capture DragOver and change e.Effect to either "Move" or "None",
depending on whether the user is dragging to a proper node.
3. Capture DragDrop so I can make the final changes.

The problem is, "DragDrop" (and MouseUp, for that matter) does not
fire if, in "DragOver" I have set the Effect to None. I find this
very conterintuitive. Even though the user has released the dragged
node to an illegal location, I still want to tell him why it is
illegal. Am I doing something wrong.

Also, I notice that some applications, like My Computer, are able to
personalize the cursor during certain drag operations, beyond the ones
offered in DragDropEffects. How is this done?
 
P

Peter Duniho

Dom said:
I'm using a TreeView and I want the user to drag and drop the nodes to
change the look of the tree, just like we change file-locations in "My
Computer". I do the following:

1. Capture MouseDown and start DoDragDrop.
2. Capture DragOver and change e.Effect to either "Move" or "None",
depending on whether the user is dragging to a proper node.
3. Capture DragDrop so I can make the final changes.

The problem is, "DragDrop" (and MouseUp, for that matter) does not
fire if, in "DragOver" I have set the Effect to None. I find this
very conterintuitive. Even though the user has released the dragged
node to an illegal location, I still want to tell him why it is
illegal. Am I doing something wrong.

No. Drag-and-drop is kind of funny in Windows. You initiate it by
calling DoDragDrop(). At that point, that method completely takes over,
handling all the user input, other than calling back to the original
control's code to ask about state during the operation.

You don't get control back until DoDragDrop() returns, by which time the
user has released the mouse button or otherwise cancels the operation.
So your control won't get the mouse events during the operation,
including the mouse-up.

Note that this is similar to what can happen during normal mouse
capturing even in non-drag-and-drop operations. For example, if the
user clicks in your control, then task-switches away from your
application, and then finally releases the mouse button, you won't get a
mouse-up event for that either, because the task-switch has transferred
control to some other process.
Also, I notice that some applications, like My Computer, are able to
personalize the cursor during certain drag operations, beyond the ones
offered in DragDropEffects. How is this done?

I'm not sure what you mean by "My Computer". That's not an application.
It's a specific "special" location you can navigate to from within the
Windows Explorer shell.

But, if you're asking how other applications personalize the cursor, the
answer is simple: they specifically set the cursor as appropriate. In
fact, the MSDN code sample for the DoDragDrop() method documentation
shows an example of customizing the cursors. (Of course, the Windows
Explorer shell is not, AFAIK, a managed application, so it's not using
the .NET code you see in the sample...but it's the same basic idea).

Pete
 
P

Peter Duniho

Dom said:
I'm using a TreeView and I want the user to drag and drop the nodes to
change the look of the tree, just like we change file-locations in "My
Computer". I do the following:

1. Capture MouseDown and start DoDragDrop.
2. Capture DragOver and change e.Effect to either "Move" or "None",
depending on whether the user is dragging to a proper node.
3. Capture DragDrop so I can make the final changes.

The problem is, "DragDrop" (and MouseUp, for that matter) does not
fire if, in "DragOver" I have set the Effect to None. I find this
very conterintuitive. Even though the user has released the dragged
node to an illegal location, I still want to tell him why it is
illegal. Am I doing something wrong. [...]

Sorry...I didn't really answer the underlying question in my previous post.

If you want to provide feedback to the user, you can overload one of the
non-None states. You can still set the custom cursor according to the
actual result, and then check for whether the drop operation is actually
valid in the DragDrop event, displaying your alert if it's not.

At least, I think that's how you have to do it. I don't think the
DragDrop event is raised if you've previously set the effect to None.

Pete
 
D

Dom

Dom said:
I'm using a TreeView and I want the user to drag and drop the nodes to
change the look of the tree, just like we change file-locations in "My
Computer".  I do the following:
1.  Capture MouseDown and start DoDragDrop.
2.  Capture DragOver and change e.Effect to either "Move" or "None",
depending on whether the user is dragging to a proper node.
3.  Capture DragDrop so I can make the final changes.
The problem is, "DragDrop" (and MouseUp, for that matter) does not
fire if, in "DragOver" I have set the Effect to None.  I find this
very conterintuitive.  Even though the user has released the dragged
node to an illegal location, I still want to tell him why it is
illegal.  Am I doing something wrong. [...]

Sorry...I didn't really answer the underlying question in my previous post.

If you want to provide feedback to the user, you can overload one of the
non-None states.  You can still set the custom cursor according to the
actual result, and then check for whether the drop operation is actually
valid in the DragDrop event, displaying your alert if it's not.

At least, I think that's how you have to do it.  I don't think the
DragDrop event is raised if you've previously set the effect to None.

Pete

Thanks for the info, but can you give me a little hint about "overload
one of the non-None States". The only thing I know about is the
Effect property in the DragDropEventArgs, which can be set to "Move",
"Copy", "None", etc. I see nothing about a State.
 
P

Peter Duniho

Dom said:
Thanks for the info, but can you give me a little hint about "overload
one of the non-None States". The only thing I know about is the
Effect property in the DragDropEventArgs, which can be set to "Move",
"Copy", "None", etc. I see nothing about a State.

I wrote "state", not "State".

I'm not using the word "overload" in the technical sense, as you would
understand it for methods. I just mean, when you would have used
"None", instead just use "Move" and then where you need to provide user
feedback (i.e. set the cursor) and handle the operation (i.e. in the
DragDrop event handler), use the additional information you have to
distinguish the two (i.e. whatever it is that distinguishes between a
legal location and an illegal one for which it's useful to provide an
error message to the user).

Pete
 
D

Dom

I wrote "state", not "State".

I'm not using the word "overload" in the technical sense, as you would
understand it for methods.  I just mean, when you would have used
"None", instead just use "Move" and then where you need to provide user
feedback (i.e. set the cursor) and handle the operation (i.e. in the
DragDrop event handler), use the additional information you have to
distinguish the two (i.e. whatever it is that distinguishes between a
legal location and an illegal one for which it's useful to provide an
error message to the user).

Pete

All clear now. Thanks a bunch. It was easier than I thought.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top