Team LiB
Previous Section Next Section

Highlighting Nodes

Before I move on to the next subject, I want to say one last thing about the TreeDragOver delegate. This is the one that highlights the node under the cursor while you are dragging a photo. There is a line in here that sets the focus to the TreeView control. If you comment this line out and run the program, you will still get highlighting, but it will be gray.

In the SetupTree function I include a line of code to set the HideSelection property to false. It is this property that allows the gray selection of the node even without setting the focus to the node.

Try commenting this HideSelection code out, and also comment out the set focus line in the TreeDragOver function. Now when you drag an item over a node, you will not see any highlighting at all.

My point here is this: Leave the HideSelection code in there and cut out the set focus code. Adding the set focus code will definitely cause problems later when 6 months down the line you or someone else will write a delegate that hooks to the GotFocus event of your TreeView. All of a sudden, tons of code will run at the wrong time when you drag an object over your nodes. Forcing the tree to get focus in this code will fire the GotFocus event.

Although it is nice to see the node properly selected, it is not worth the headache of possible future bugs. Use the "HideSelection = false" method of highlighting instead.


Team LiB
Previous Section Next Section