Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(ebook) Visual Studio .NET Mastering Visual Basic.pdf
Скачиваний:
120
Добавлен:
17.08.2013
Размер:
15.38 Mб
Скачать

SUMMARY 789

I’ve included these statements in the Globe project on the CD, but they’re commented out. To test the commands of the File menu of the Globe application, add a few items to the TreeView control (countries and cities) and save the tree to a disk file. Then select the root node, delete it with the Delete Current Node button, and load the file you just saved to disk.

One last remark about the code that loads a TreeView control from a disk file. Since the TreeView is persisted to an XML file, the user may attempt to open an XML file that contains irrelevant data. You must insert a structured exception handler to avoid runtime errors, or use a new extension for these files. After looking at the XML files generated by the Serialize method for a couple of TreeView controls, you should change the SoapFormatter to a BinaryFormatter.

Summary

The controls discussed in this chapter are among the more advanced ones. With the possible exception of the data-bound controls, which are discussed in the fourth part of the book, you have all the information you need to start building elaborate user interfaces.

The TreeView and ListView controls are highly visual. Not only do they display the necessary information, but they also make it easy for the user to see how the information is structured. They’re not commonly used in the user interface design, even by intermediate programmers, but they can add a professional touch to your applications. As you have seen, they’re not especially hard to program either. Once you understand the relation between a node and its Nodes collection and how to create items with subitems, you’ll be able to use them just like any other control.

The recursive procedure for scanning a TreeView control may have thrown off some of you. If you have read Chapter 13, you have seen a similar procedure for scanning folders. As the object models become more and more complicated, recursive programming will become a necessity in everyday programming. If you’re not comfortable with this topic, please read a detailed tutorial on recursive programming in Chapter 18 of this book. Recursion is a very powerful coding technique, and it will simplify enormously some of your coding tasks, as demonstrated in the examples of this chapter.

Copyright ©2002 SYBEX, Inc., Alameda, CA

www.sybex.com