Drag and drop databound treeview WPF
-
Yesterday I had a great experience designing an application in WPF. It's really cool to see how easy it was to create a databound treeview. However, I want to drag nodes within the treeview. So far I did the following: - Implement a mousemove eventhandler that initiates the drag operation - Implement a dragover eventhandler to check if a dragged item can be dropped - Implement a drop eventhandler that moves the item. However the last eventhandler proves to be problematic. Although I have the correct data, I can't seem to grab the treeviewitem that th mouse is currently over. Anybody knows how I can get this?
WM. What about weapons of mass-construction? "What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson
-
Yesterday I had a great experience designing an application in WPF. It's really cool to see how easy it was to create a databound treeview. However, I want to drag nodes within the treeview. So far I did the following: - Implement a mousemove eventhandler that initiates the drag operation - Implement a dragover eventhandler to check if a dragged item can be dropped - Implement a drop eventhandler that moves the item. However the last eventhandler proves to be problematic. Although I have the correct data, I can't seem to grab the treeviewitem that th mouse is currently over. Anybody knows how I can get this?
WM. What about weapons of mass-construction? "What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson
-
Try searching through articles, I remember running across a good one dealing more or less with your issue just this week but sorry I cant remember the title not the author.
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)
Found an article explaining a dragdropmanager for a listview: http://www.codeproject.com/WPF/ListViewDragDropManager.asp[^] Going to read that and see if it fits my application as well.
WM. What about weapons of mass-construction? "What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson
-
Found an article explaining a dragdropmanager for a listview: http://www.codeproject.com/WPF/ListViewDragDropManager.asp[^] Going to read that and see if it fits my application as well.
WM. What about weapons of mass-construction? "What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson
Thanks Willem, I've been through that one as well, it's also good.. I found the one I just told you about. You may wanna take a look at it as well. Cheers,
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)
-
Thanks Willem, I've been through that one as well, it's also good.. I found the one I just told you about. You may wanna take a look at it as well. Cheers,
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)
Unfortunatly that one is for Windows Forms, however I did manage to get a bit further with detecting the item that the source item is being dragged on. Now to fix the last bugs, because now it seems as if the MouseMove event is no longer fired if you iniated a drag operation.
WM. What about weapons of mass-construction? "What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson
-
Unfortunatly that one is for Windows Forms, however I did manage to get a bit further with detecting the item that the source item is being dragged on. Now to fix the last bugs, because now it seems as if the MouseMove event is no longer fired if you iniated a drag operation.
WM. What about weapons of mass-construction? "What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson
-
Good, I think I'll be into WPF or WTF;P soon.. No seriously, I'm interested, it sounds quite sexy:rolleyes:
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)
As it turned out the solution was moderatly simple. I had to do the following in the drop eventhandler:
Task t = (Task)e.Data.GetData(typeof(Task));
_currentMousePosition = MouseUtilities.GetMousePosition(taskTree);
HitTestResult result = VisualTreeHelper.HitTest(taskTree, _currentMousePosition);if (result.VisualHit is FrameworkElement)
{
_targetTask = (result.VisualHit as
FrameworkElement).DataContext as Task;}
After that it's just removing the task from the original parent and add it to the new parent. Pretty easy :D Too bad the mouse handling in WPF sucks, because I had to rely on Josh Smith's MouseUtilities class to get the actual mouse position relative to the treeview. Maybe I will build a dragdropmanager for the treeview similar to the one Josh created. It makes life a lot easier.
WM. What about weapons of mass-construction? "What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson