Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Initiating drag from a TreeView

 
 
Old 06-21-2006   #1 (permalink)
John Dunn


 
 

Initiating drag from a TreeView

I am having difficulty in initiating a drag operation from my TreeView. This
seems like it should be a simple thing to accomplish but for the life of me I
can't figure it out. I'd expect there to be some methods to override like
OnDragBegin but I only see overrides for handling the drop operations (
OnDragEnter, OnDragOver, OnDrop ).

I'm guessing that I need to use DoDragDrop somewhere but I'm not sure where.
Do I need to handle mouse down/move and check to see if the user has started
to drag? I'd hope not - writing the same thing using straight Win32 is as
simple as handling the TVN_BEGINDRAG message. That way the OS handles the
drag delta checking.

I'm hoping this is something simple I'm overlooking-

Thanks-

John

My System SpecsSystem Spec
Old 06-21-2006   #2 (permalink)
Drew Marsh


 
 

Re: Initiating drag from a TreeView

John Dunn wrote:

> I am having difficulty in initiating a drag operation from my
> TreeView. This seems like it should be a simple thing to accomplish
> but for the life of me I can't figure it out. I'd expect there to be
> some methods to override like OnDragBegin but I only see overrides for
> handling the drop operations ( OnDragEnter, OnDragOver, OnDrop ).
>
> I'm guessing that I need to use DoDragDrop somewhere but I'm not sure
> where. Do I need to handle mouse down/move and check to see if the
> user has started to drag? I'd hope not - writing the same thing using
> straight Win32 is as simple as handling the TVN_BEGINDRAG message.
> That way the OS handles the drag delta checking.
>
> I'm hoping this is something simple I'm overlooking-


Have a look at this post[1] and this post[2]. They should answer your questions.

HTH,
Drew

[1] http://blogs.msdn.com/marcelolr/arch...02/542641.aspx
[2] http://blogs.msdn.com/marcelolr/arch...09/547923.aspx
___________________________________
Drew Marsh
Chief Software Architect
Mimeo.com, Inc. - http://www.mimeo.com
Microsoft C# / WPF MVP
Weblog - http://blog.hackedbrain.com/


My System SpecsSystem Spec
Old 06-21-2006   #3 (permalink)
John Dunn


 
 

Re: Initiating drag from a TreeView

Looking at those 2 posts it looks like it's up to me to handle the drag
detection. The problem is that TreeView::OnMouseDown only gets called when I
click on the background of the treeview and not when I click on a
TreeViewItem. It looks like it's possible to override
TreeViewItem::OnMouseDown - is that the correct way to go about this? It
seems odd that I need to derive from TreeViewItem just to get drag and drop
working but if that's what it takes then I guess I'll do it.

Thanks-

John

"Drew Marsh" wrote:

> John Dunn wrote:
>
> Have a look at this post[1] and this post[2]. They should answer your questions.
>
> HTH,
> Drew
>
> [1] http://blogs.msdn.com/marcelolr/arch...02/542641.aspx
> [2] http://blogs.msdn.com/marcelolr/arch...09/547923.aspx
> ___________________________________
> Drew Marsh
> Chief Software Architect
> Mimeo.com, Inc. - http://www.mimeo.com
> Microsoft C# / WPF MVP
> Weblog - http://blog.hackedbrain.com/
>
>
>

My System SpecsSystem Spec
Old 06-22-2006   #4 (permalink)
Drew Marsh


 
 

Re: Initiating drag from a TreeView

John Dunn wrote:

> Looking at those 2 posts it looks like it's up to me to handle the
> drag detection. The problem is that TreeView::OnMouseDown only gets
> called when I click on the background of the treeview and not when I
> click on a TreeViewItem. It looks like it's possible to override
> TreeViewItem::OnMouseDown - is that the correct way to go about this?
> It seems odd that I need to derive from TreeViewItem just to get drag
> and drop working but if that's what it takes then I guess I'll do it.


I believe it's because the mouse down event is being "handled" by the treeview
nodes. You need to listen for the routed event and handle "handled" events
too. Like so:

// The key here is the third parameter that indicates you want to be notified
about events even if they're handled already
this.myTreeView.AddHandler(Mouse.MouseDownEvent, new RoutedEventHandler(this.myTreeView_MouseDown),
true);


private void myTreeView_MouseDown(object source, RoutedEventArgs args)
{
TreeViewItem item = args.Source as TreeViewItem

if(item != null)
{
// Start your drag drop operation here
}
}

HTH,
Drew


My System SpecsSystem Spec
Old 06-22-2006   #5 (permalink)
John Dunn


 
 

Re: Initiating drag from a TreeView

Thanks - that did the trick!

"Drew Marsh" wrote:

> John Dunn wrote:
>
> > Looking at those 2 posts it looks like it's up to me to handle the
> > drag detection. The problem is that TreeView::OnMouseDown only gets
> > called when I click on the background of the treeview and not when I
> > click on a TreeViewItem. It looks like it's possible to override
> > TreeViewItem::OnMouseDown - is that the correct way to go about this?
> > It seems odd that I need to derive from TreeViewItem just to get drag
> > and drop working but if that's what it takes then I guess I'll do it.

>
> I believe it's because the mouse down event is being "handled" by the treeview
> nodes. You need to listen for the routed event and handle "handled" events
> too. Like so:
>
> // The key here is the third parameter that indicates you want to be notified
> about events even if they're handled already
> this.myTreeView.AddHandler(Mouse.MouseDownEvent, new RoutedEventHandler(this.myTreeView_MouseDown),
> true);
>
>
> private void myTreeView_MouseDown(object source, RoutedEventArgs args)
> {
> TreeViewItem item = args.Source as TreeViewItem
>
> if(item != null)
> {
> // Start your drag drop operation here
> }
> }
>
> HTH,
> Drew
>
>
>

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Need help on treeview VB Script
An Error has occurred initiating the Virtual Key Shared Cache... Vista performance & maintenance
Explorer treeview +/- Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46