Skip to main content

DisplayTreeView: Part 1

The DisplayTreeView method creates the tree for the left hand side of the GUI. In this example (covering this page and the following page), you will add the code that creates the tree and adds the Name property for each Contact.

DisplayTreeView creates two level 1 nodes: BusinessNode and PersonalNode. For each Contact instance, DisplayTreeView creates a node containing the Name and ID values. The Name property is displayed by the node. The ID value is stored in the node's Tag property. DisplayTreeView then adds the node to the appropriate level 1 node depending upon the value of the Contact instance's ContactType property.

The first part of the method does the following:

  1. Declares the contactNode variable.

  2. Invokes BeginUpdate on treeView1. This prevents the display of the tree from being painted while the tree is being built or rebuilt.

  3. Creates the level 1 nodes PersonalNode and BusinessNode.

 private void DisplayTreeView()
   TreeNode contactNode = null;
   TreeNode phoneNode = null;
   TreeNode PersonalNode = new TreeNode("Personal");
   TreeNode BusinessNode = new TreeNode("Business");


The exercise for Part III asks you to modify DisplayTreeView so that it displays the phone number information as well as the contact names.

FeedbackOpens in a new tab