Add run-time editing, drag-and-drop features and persistence to the TreeView control.
by Evangelos Petroutsos
Oct 21, 2002
Page 1 of 5
he TreeView control is one of the most flexible Windows controls. It displays hierarchical data and lets users navigate through the hierarchy by expanding and collapsing nodes at will. I may be slightly biased, but I think it's an awesome tool for building functional Windows interfaces. Yet TreeView controls haven't received the attention they deserve, probably because, as delivered, they're not easy to use in many real-world situations, where users must be able to insert, delete, edit, rearrange, and save the items. This tutorial shows you how to solve these problems.
The downloadable TVEdit sample application (see Figure 1), demonstrates a range of TreeView techniques. It lets you populate a TreeView control at run time, edit the node text, drag and drop nodes, moving them from one position to another, persist the nodes to an XML file and reload a TreeView control from the persisted XML file at some future point.