![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
| | #3 (permalink) |
| 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 Specs![]() |
| | #4 (permalink) |
| 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 Specs![]() |
| | #5 (permalink) |
| 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 Specs![]() |
![]() |
| 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 |