views:

121

answers:

1

I'm handling drag and drop events in a TreeView using PreviewMouseDown, PreviewMouseMove and PreviewMouseUp, however, there is an issue.

In my PreviewMouseDown handler, I set everything ready in case there's a drag started (detected in the Move event), however I set e.Handled = true. This means that standard selection events don't get generated on my tree!

What I want to be able to do in my Up event is to invoke the standard treeview selection changed event - except I cannot call events outside of the tree. So what's the correct way to do this?

I have tried using the standard MouseDown, MouseMove and MouseUp events however there's an issue with messing up my multiple selection feature that means I need to use the Preview version of those events.

A: 

My solution to this is to not use the Preview handlers, instead I use MouseDown, MouseMove and MouseUp.

The sequence of events is:

* MouseDown (set up for possible drag)
* SelectionChanged (remember any selection change)
* MouseMove (here we might go into a drag operation)
* MouseUp (if we went into a drag operation, all done, otherwise process the multiple selection stuff)
imekon
The SelectionChanged event doesn't tell you anything if you click on the same item twice. That makes CTRL-Click tricky if you want to toggle selection on the same item.
imekon