Ask a questionAsk a question
 

AnswerNodeCollection -> TreeNodeCollection

  • Wednesday, January 16, 2008 3:08 PMNeoPunk Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi!
    I'm working now at query builder for work items(like Team Explorer), major portion is left. For Area Path i make my own control using combobox and tree view. I want add into TreeView project nodes.

    ProjectCollection collection = store.Projects;
    TreeNodeConverter c = TreeNodeConverter.;
    foreach (Project p in collection)
    {
    NodeCollection nodes = p.AreaRootNodes;
    foreach (Node node in nodes)
    {
    ......
    }

    Project.AreaRoots return NodeCollection object and i need TreeNodeCollection to and it's into TreeView.
    How can i convert NodeCollection into TreeNodeCollection?

    Thanks.



Answers

  • Friday, January 18, 2008 1:47 AMHayder CaseyMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

     

    I am not sure if there is code to do the conversion. but It is not hard to code a converter yourself

     

    Here is a sample snippet to do the conversion (please note that I have not tested this)

     

    Code Block

     

    TreeNodeCollection NodeCollectionToTreeNodeCollection(NodeCollection nodeCollection)

    {

    TreeNodeCollection result = new TreeNodeCollection();

    foreach (Node node in NodeCollection)

    {

    result.Add(NodeToTreeNode(node));

    }

    return result;

    }

    //constructs a TreeNode from a node

    TreeNode NodeToTreeNode(Node node)

    {

    TreeNode treeNode = new TreeNode(node.Name);

    foreach (Node child in node.ChildNodes)

    {

    treeNode.Nodes.Add(NodeToTreeNode(child));

    }

    return treeNode;

    }

     

    Hope this helps;

All Replies

  • Friday, January 18, 2008 1:47 AMHayder CaseyMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

     

    I am not sure if there is code to do the conversion. but It is not hard to code a converter yourself

     

    Here is a sample snippet to do the conversion (please note that I have not tested this)

     

    Code Block

     

    TreeNodeCollection NodeCollectionToTreeNodeCollection(NodeCollection nodeCollection)

    {

    TreeNodeCollection result = new TreeNodeCollection();

    foreach (Node node in NodeCollection)

    {

    result.Add(NodeToTreeNode(node));

    }

    return result;

    }

    //constructs a TreeNode from a node

    TreeNode NodeToTreeNode(Node node)

    {

    TreeNode treeNode = new TreeNode(node.Name);

    foreach (Node child in node.ChildNodes)

    {

    treeNode.Nodes.Add(NodeToTreeNode(child));

    }

    return treeNode;

    }

     

    Hope this helps;
  • Monday, January 21, 2008 8:27 AMNeoPunk Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi!
    Thank you very much, your submission was very helpful.
  • Thursday, November 05, 2009 2:56 PMViDom Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    TreeNodeCollection result = new TreeNodeCollection();

    TreeNodeCollection result = new TreeNode().Nodes;