Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.

For information on migrating to InterSystems IRIS, see Why Migrate to InterSystems IRIS?

DisplayTreeView: Part 2

The second part of DisplayTreeView does the following:

  1. Iterates through each Contact object ID stored in ContactList and opens the corresponding Contact instance. Note that the code uses the using statement to ensure that the Contact instances are properly disposed of.

  2. If a Contact instance has ContactType value “Personal”, the method creates a node containing its information and adds it to PersonalNode as a subnode.

  3. If a Contact instance has ContactType value “Business”, the method creates a new node containing its information and adds it to BusinessNode as a subnode.

  4. Adds BusinessNode and PersonalNode to treeView1 (the root node).

  5. Invokes EndUpdate. This allows the tree to be painted on the form.

Here is the second part of the method. Add the body of the method to the DisplayTreeView stub in PhoneFormObj.cs.


...
foreach (string id in ContactList)
{
 using (Contact contact = Contact.OpenId(cnCache, id))
 {
   if (contact.ContactType.Equals("Personal"))
   {
    contactNode = new TreeNode(contact.Name);
    contactNode.Name = "Name Node";
    contactNode.Tag = id;
    PersonalNode.Nodes.Add(contactNode);
    }
  if (contact.ContactType.Equals("Business"))
  {
   contactNode = new TreeNode(contact.Name);
   contactNode.Tag = id;
   contactNode.Name = "Name Node";
   BusinessNode.Nodes.Add(contactNode);
   }
  }
 }
treeView1.Nodes.Add(PersonalNode);
treeView1.Nodes.Add(BusinessNode);
treeView1.EndUpdate();
}
Feedback