Skip to content

Instantly share code, notes, and snippets.

@brennanneoh
Created February 4, 2012 02:13

Revisions

  1. Brennan Neoh revised this gist Feb 4, 2012. 1 changed file with 46 additions and 0 deletions.
    46 changes: 46 additions & 0 deletions gistfile1.cs
    Original file line number Diff line number Diff line change
    @@ -4,3 +4,49 @@
    //Using SharePoint object model to retrieve both lists
    objMembersList = objCurrentWeb.Lists["Project Members"];
    objContactsList = objCurrentWeb.Lists["Project Contacts"];

    //looping through the Members list
    foreach (SPListItem objMembersListItem in objMembersList.Items)
    {
    //if the Job title is "Country Representative"
    if (Convert.ToString(objMembersListItem["Job Title"]) == "Country Representative")
    {
    //create a top level node for the treeview control
    TreeNode objMainTreeNode = new TreeNode();
    //the text property of the node will have the following format: Carlos Gomez (Mexico) - FirstName LastName (country)
    objMainTreeNode.Text = objMembersListItem["First name"].ToString() + " "
    + objMembersListItem["Last name"].ToString()
    + " (" + objMembersListItem["Representing"].ToString() + ")";
    //the value property of the node will be eqal to the country this person is representing
    objMainTreeNode.Value = objMembersListItem["Representing"].ToString();
    //the new node is added to the nodes collection of the treeview control
    trvContacts.Nodes.Add(objMainTreeNode);
    }
    }

    foreach (SPListItem objContactsListItem in objContactsList.Items)
    {
    //for each contact look through the top level nodes in the treeview control and determine under which representative that particular contacts goes
    foreach (TreeNode objMainTreeNode in trvContacts.Nodes)
    {
    //if the country of the contact is equal to the county of the representative
    if (objContactsListItem["Country"].ToString() == objMainTreeNode.Value)
    {
    //a new node under that top level node is created
    objSubTreeNode = new TreeNode();
    //the text property of the contact node will have the following format: Juan Garcia (IBM) - FirstName LastName (company)
    objSubTreeNode.Text = objContactsListItem["First name"].ToString() + " "
    + objContactsListItem["Last name"].ToString() +
    " (" + objContactsListItem["Company"].ToString() + ")";
    //the value property of the contact node will have the following format: FirstName$LastName$company (the $ sign is used as separator)
    objSubTreeNode.Value = objContactsListItem["First name"].ToString() + "$"
    + objContactsListItem["Last name"].ToString() + "$"
    + objContactsListItem["Company"].ToString();
    //the new node is added to the ChildNodes collection of the top level node
    objMainTreeNode.ChildNodes.Add(objSubTreeNode);
    break;
    }
    }
    }

    trvContacts.ExpandAll();
  2. Brennan Neoh created this gist Feb 4, 2012.
    6 changes: 6 additions & 0 deletions gistfile1.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    //obtaining reference to the current web (i.e. the web site which was defined when setting up the project in Visual Studio (in our case http://win7:8000/sites/QATP1PTS/)
    objCurrentWeb = SPContext.Current.Web;

    //Using SharePoint object model to retrieve both lists
    objMembersList = objCurrentWeb.Lists["Project Members"];
    objContactsList = objCurrentWeb.Lists["Project Contacts"];