Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Drag and drop databound treeview WPF

Drag and drop databound treeview WPF

Scheduled Pinned Locked Moved C#
csharpwpfquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WillemM
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • W WillemM

      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

      M Offline
      M Offline
      Muammar
      wrote on last edited by
      #2

      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) (><)

      W 1 Reply Last reply
      0
      • M Muammar

        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) (><)

        W Offline
        W Offline
        WillemM
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • W WillemM

          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

          M Offline
          M Offline
          Muammar
          wrote on last edited by
          #4

          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) (><)

          W 1 Reply Last reply
          0
          • M Muammar

            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) (><)

            W Offline
            W Offline
            WillemM
            wrote on last edited by
            #5

            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

            M 1 Reply Last reply
            0
            • W WillemM

              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

              M Offline
              M Offline
              Muammar
              wrote on last edited by
              #6

              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) (><)

              W 1 Reply Last reply
              0
              • M Muammar

                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) (><)

                W Offline
                W Offline
                WillemM
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups