Hello everyone,
Yesterday I posted a message about implementing drag & drop in a TreeView
control.
I'm having real difficulty getting this to work -- the process seems to be
incredibly delicately balanced and finding my way through it has descended
into one of those awful situations which I refer to as guess & test.
From the point at which DoDragDrop() function is called until some later
time when the process is completed there is clearly a lot going on in the
background while the .NET drag/drop code takes over the process. For what I
need the dragnode and the dropnode are both TreeNodes in the same TreeView
control. While the process is going on I need to intervene to determine
whether or not dragging a node is allowed and whether or not dropping on the
current 'over node' is allowed and so on.
The difficulties that I'm having can be summarised:
1. The .NET drag/drop code appears to impede other things from ccurring. I
can see how this makes sense but writing debug/confirmation text to the
console (as in: System.Console.WriteLine("msg")) is one thing that can't be
done while dragging is under framework control and this is not helpful.
2. The event ItemDrag fires but neither QueryContinueDrag nor GiveFeedback
fire. The documentation indicates that they are to fire after ItemDrag but
they certainly don't appear to be doing so. The documentation is ambiguous
about whether or not QueryContinueDrag and GiveFeedback fire repeatedly
afterwards but since they don't appear to be firing anyway, I can't figure
that one out.
3. The DragDropEffects object is its own master and seems to have decided
that it doesn't need to pay attention to what I tell it to do. That sounds a
little snotty, doesn't it? -- sorry about that -- it reflects my level of
frustration. Anyway, the effect drops back into DragDropEffects.None (which
gives rise to the "No Parking" cursor) even though I have issued explicit
DragDropEffects.Move or DragDropEffects.Copy.
4. Since I can't change the cursor myself (because GiveFeedback is not
firing) I have resorted to changing the background colour of the nodes to
give visual validity feedback to the user. This works up to a point. As the
cursor moves over nodes I changing the colour to red to say "can't drop
here..." or green to say "...but here is OK". When the cursor moves off a
portential target node I need the background colour to revert to the
'ambient' background to the treeview and this is where things come unstuck.
Changing the colour back causes the underlying code to revert to
DragDropEffects.None and the behaviour is as if dragging is disallowed
altogether. The code to change the colour appears to be independant of
anything the the framework might be doing but obviously it isn't and why
changing the background colour should affect the framework code is pretty
hard to understand.
5. I would happily avoid all of this and implement my own drag code if it
were not for the problem I described in yesterday's post; i.e., The MouseDown
and MouseUp events occur simultaneously even though the physical button has
not been released. Why is this happening?
I'm finding this all very puzzling. There seem to be stumbling blocks in
every direction with this process. Comments and suggestions would be
welcomed. In the meantime I will continue to bang my head against it. This
part of the process always produces a result even if it is just a headache.
--
Kia pai tō haere, e hoa mā!
Nā Plumer