Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Initiating drag from a TreeView

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 06-21-2006   #1 (permalink)
John Dunn
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help on treeview Boein VB Script 2 07-18-2008 02:18 AM
An Error has occurred initiating the Virtual Key Shared Cache... jrt773 Vista performance & maintenance 1 06-28-2008 11:38 PM
TreeView, TreeViewItem knallkopf66 Avalon 1 08-16-2007 08:24 PM
ListView / TreeView, multiple selection and drag/drop =?Utf-8?B?RGlyaw==?= Avalon 0 07-16-2006 02:36 PM
Drag and Drop Treeview Items between 2 Treeview ProjectGKR Avalon 3 03-14-2006 07:29 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51