Towards a more functional TreeView
Over the past few days questions have been rolling in on the Windows Forms .NET Forums over the functionlity of the TreeView control in Windows Forms. There really isn't any relief for these questions since the basic control only thunks out to the Win32 version of the TreeView which is itself, not extremely functional. Among the questions currently being posed are:
- Why can't the TreeNodes be shared amongst several TreeView controls? I'm guessing some individuals are actually swapping the nodes back and forth for some type of filtered view scenario. It can be a reall pita to have to clone the nodes all the time, and if nodes begin to run through the edit process, you don't even want to know about all the code that has to go in for synchronization.
- How do I do a meaningful merge of two sets of TreeNodes? This would actually answer some of your synchronization questions, unless you wanted real-time synchronization. Basically, merge the cloned tree nodes back into the main tree at some point. The algorithm isn't expressly difficult, but it doesn't exist, and that confuses quite a few people. Currently, if you try to just add the nodes back into the three, you'll end up with two versions of the nodes. I did manage to come up with an answer to this one over on the Forums.
- The most pressing complaint I've heard is actually over on the Avalon newsgroups. There is some big debate on how cool the Avalon TreeView will actually be and I'm enjoying sitting on the sidelines and watching the feature requests role in. I'm thinking the coolest feature request I've seen so far is in regards to how the tree is rendered. Seems people want a general purpose hierarchical container where each node can be any form of UI element that you might want to render. Think about that for a minute, because the UI implications and different types of views start to become limitless with a relatively small amount of code.
Well, I have to say I love the TreeView control myself. There are some issues everyone runs into when using a really nice control with huge numbers of features, but with a little patience most of them can be overcome. Shared TreeNodes you want? Then generate a factory object that maintains listings of peer nodes and manages the property changes so they propagate around. Merging nodes you think you should have? Check out my code samples posting and see if the algorithm might be useful to you. General purpose hierarchical display you say? Well wait for Longhorn and play with the developer preview release because you might be seeing a really cool tree implementation in the near future.