• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TreeNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中TreeNode的典型用法代码示例。如果您正苦于以下问题:C# TreeNode类的具体用法?C# TreeNode怎么用?C# TreeNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TreeNode类属于命名空间,在下文中一共展示了TreeNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: expandAllParents

 private void expandAllParents(TreeNode node)
 {
     while (node.Parent != null) {
         node.Parent.Expanded = true;
         node = node.Parent;
     }
 }
开发者ID:kyvkri,项目名称:mgone,代码行数:7,代码来源:Default.aspx.cs


示例2: GetTree

        public async Task<TreeNode<NavigationNode>> GetTree()
        {
            // ultimately we will need to cache sitemap per site
            // we will implement a custom ICacheKeyResolver to resolve multi tenant cache keys

            if (rootNode == null)
            {
                log.LogDebug("rootnode was null so checking cache");
                string cacheKey = cacheKeyResolver.ResolveCacheKey(options.CacheKey);

                rootNode = (TreeNode<NavigationNode>)cache.Get(cacheKey);
               
                if(rootNode == null)
                {
                    log.LogDebug("rootnode was not in cache so building");
                    rootNode = await implementation.GetTree();
                    if (rootNode != null)
                    {
                        cache.Set(
                            cacheKey,
                            rootNode,
                            new MemoryCacheEntryOptions()
                            .SetSlidingExpiration(TimeSpan.FromSeconds(options.CacheDurationInSeconds)));
                    }
                }
                else
                {
                    log.LogDebug("rootnode was found in cache");
                }
                
            }

            return rootNode;
        }
开发者ID:lespera,项目名称:cloudscribe.Web.Navigation,代码行数:34,代码来源:MemoryCacheNavigationTreeBuilder.cs


示例3: PopulateTreeView

    public void PopulateTreeView(string directoryValue, TreeNode parentNode )
    {
        string[] directoryArray =
           Directory.GetDirectories( directoryValue );

          try
          {
             if ( directoryArray.Length != 0 )
             {
                foreach ( string directory in directoryArray )
                {
                  substringDirectory = directory.Substring(
                  directory.LastIndexOf( '\\' ) + 1,
                  directory.Length - directory.LastIndexOf( '\\' ) - 1 );

                  TreeNode myNode = new TreeNode( substringDirectory );

                  parentNode.Nodes.Add( myNode );

                  PopulateTreeView( directory, myNode );
               }
             }
          } catch ( UnauthorizedAccessException ) {
            parentNode.Nodes.Add( "Access denied" );
          } // end catch
    }
开发者ID:dbremner,项目名称:hycs,代码行数:26,代码来源:treeview.cs


示例4: BuildBinarySearchTree

        /// <summary>
        /// Build a Binary search tree for testing purpose
        /// </summary>
        /// <returns>The root node of the tree</returns>
        public static TreeNode<int> BuildBinarySearchTree()
        {
            TreeNode<int> root = new TreeNode<int>(15);
            TreeNode<int> l2l = new TreeNode<int>(13);
            TreeNode<int> l2r = new TreeNode<int>(20);
            root.Left = l2l;
            root.Right = l2r;

            TreeNode<int> l31 = new TreeNode<int>(11);
            TreeNode<int> l32 = new TreeNode<int>(14);
            TreeNode<int> l33 = new TreeNode<int>(17);

            l2l.Left = l31;
            l2l.Right = l32;
            l2r.Right = l33;

            TreeNode<int> l41 = new TreeNode<int>(9);
            TreeNode<int> l51 = new TreeNode<int>(6);
            TreeNode<int> l61 = new TreeNode<int>(5);
            TreeNode<int> l62 = new TreeNode<int>(7);

            l31.Left = l41;
            l41.Left = l51;
            l51.Left = l61;
            l51.Right = l62;

            return root;
        }
开发者ID:zwang,项目名称:CrackCodeInterviewInCSharp,代码行数:32,代码来源:TreeUtility.cs


示例5: PrintTreeByInOrder

 public static void PrintTreeByInOrder(TreeNode<int> root)
 {
     if (root == null) return;
     PrintTreeByInOrder(root.Left);
     Console.Write("{0} ", root.Value);
     PrintTreeByInOrder(root.Right);
 }
开发者ID:zwang,项目名称:CrackCodeInterviewInCSharp,代码行数:7,代码来源:TreeUtility.cs


示例6: BuildTree

 private void BuildTree()
 {
     foreach(Node idx in Data)
     {
         if(idx.Name == "Controllers")
         {
             TreeNode node = new TreeNode();
             node.ID = "idController";
             node.Text = LanguageRecords.Language.Instance["Controllers", null, "Controllers"];
             root.Controls.Add(node);
             BuildChildren(idx, node);
         }
         else if(idx.Name == "Modules")
         {
             TreeNode node = new TreeNode();
             node.ID = "idModules";
             node.Text = LanguageRecords.Language.Instance["Modules", null, "Modules"];
             root.Controls.Add(node);
             BuildChildren(idx, node);
         }
         else if(idx.Name == "Types")
         {
             TreeNode node = new TreeNode();
             node.ID = "idTypes";
             node.Text = LanguageRecords.Language.Instance["Types", null, "Types"];
             root.Controls.Add(node);
             BuildChildren(idx, node);
         }
     }
 }
开发者ID:greaterwinner,项目名称:ra-brix,代码行数:30,代码来源:ViewDetailsOfFile.ascx.cs


示例7: GetTree

        public async Task<TreeNode<NavigationNode>> GetTree()
        {
            // ultimately we will need to cache sitemap per site

            if (rootNode == null)
            {
                NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter();

                await cache.ConnectAsync();
                byte[] bytes = await cache.GetAsync(cacheKey);
                if (bytes != null)
                {
                    string xml = Encoding.UTF8.GetString(bytes);
                    XDocument doc = XDocument.Parse(xml);
                    
                    rootNode = converter.FromXml(doc);
                }
                else
                {
                    rootNode = await BuildTree();
                    string xml2 = converter.ToXmlString(rootNode);

                    await cache.SetAsync(
                                        cacheKey,
                                        Encoding.UTF8.GetBytes(xml2),
                                        new DistributedCacheEntryOptions().SetSlidingExpiration(
                                            TimeSpan.FromSeconds(100))
                                            );
                                        }

                
            }

            return rootNode;
        }
开发者ID:okusnadi,项目名称:cloudscribe,代码行数:35,代码来源:XmlNavigationTreeBuilder.cs


示例8: BindTree

    private void BindTree()
    {
        try
        {
            string TypeFlag = Request["TypeFlag"].ToString();
            if (!string.IsNullOrEmpty(TypeFlag))
            {
                DataTable dt = ApprovalFlowSetBus.GetBillTypeByType(TypeFlag);
                if (dt != null && dt.Rows.Count > 0)
                {
                    TreeNode node = new TreeNode();
                    node.Value = dt.Rows[0]["TypeFlag"].ToString();
                    node.Text = dt.Rows[0]["ModuleName"].ToString();
                    node.NavigateUrl = string.Format("javascript:javascript:void(0)");
                    BindTreeChildNodes(node);
                    Tree_BillTpye.Nodes.Add(node);
                    node.Expanded = true;
                }

                Tree_BillTpye.DataBind();
                Tree_BillTpye.Nodes[0].Selected = true;
            }
        }
        catch (Exception)
        {
            
            throw;
        }
     
    
    }
开发者ID:kosmos-zhang,项目名称:erp-aspnet,代码行数:31,代码来源:ApprovalFlowSet.aspx.cs


示例9: ConvertBST2DLL

        static TreeNode<int> ConvertBST2DLL(TreeNode<int> root, out TreeNode<int> tail)
        {
            // No null root will be passed in. So no need to check

            // Handle head.
            TreeNode<int> head;

            if (root.Left == null)
            {
                head = root;
            }
            else
            {
                head = ConvertBST2DLL(root.Left, out tail);
                tail.Right = root;
                root.Left = tail;
            }

            // Handle tail.
            if (root.Right == null)
            {
                tail = root;
            }
            else
            {
                root.Right = ConvertBST2DLL(root.Right, out tail);
                root.Right.Left = root;
            }

            // clean up tail end
            tail.Right = null;

            return head;
        }
开发者ID:yizhengc,项目名称:MyAlgorithmCode,代码行数:34,代码来源:BST2DLLConversion.cs


示例10: Tree

 public Tree(Coord root)
 {
     this.rootNode = new TreeNode();
     this.rootNode.SetRoot(root,new List<Coord>());
     this.nodes = new List<TreeNode>();
     this.nodes.Add(rootNode);
 }
开发者ID:CaveExplorerStudio,项目名称:ProjectDarkZone,代码行数:7,代码来源:Graph.cs


示例11: Process

 private void Process(TreeNode root, List<Tuple<PropertyInfo, List<String>>> input)
 {
     List<List<String>> output = new List<List<string>>();
     ISet<String> children = new HashSet<String>();
     foreach(var item in input)
     {
         children.Add(item.Item2[item.Item2.Count - 1]);
     }
     foreach(var child in children)
     {
         List<Tuple<PropertyInfo, List<String>>> owners = input.Where(item => item.Item2[item.Item2.Count - 1] == child).ToList();
         List<Tuple<PropertyInfo, List<String>>> removeds = new List<Tuple<PropertyInfo, List<string>>>();
         PropertyInfo childProp = null;
         foreach(var owner in owners)
         {
             var removed = new List<string>(owner.Item2);
             removed.RemoveAt(removed.Count - 1);
             if (removed.Count > 0)
                 removeds.Add(Tuple.Create(owner.Item1, removed));
             else
                 childProp = owner.Item1;
         }
         TreeNode childNode = new TreeNode(child);
         childNode.Parent = root;
         childNode.Property = childProp;
         root.Children.Add(childNode);
         Process(childNode, removeds);
     }
 }
开发者ID:ekospinach,项目名称:kawaldesa,代码行数:29,代码来源:SpreadsheetHeaders.cs


示例12: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
		if (!Page.IsPostBack)
		{
			DataSet ds = GetProductsAndCategories();

			// Loop through the category records.
			foreach (DataRow row in ds.Tables["Categories"].Rows)
			{
				// Use the constructor that requires just text
				// and a non-displayed value.
				TreeNode nodeCategory = new TreeNode(
					row["CategoryName"].ToString(),
					row["CategoryID"].ToString());

				TreeView1.Nodes.Add(nodeCategory);

				// Get the children (products) for this parent (category).
				DataRow[] childRows = row.GetChildRows(ds.Relations[0]);

				// Loop through all the products in this category.
				foreach (DataRow childRow in childRows)
				{
					TreeNode nodeProduct = new TreeNode(
						childRow["ProductName"].ToString(),
						childRow["ProductID"].ToString());
					nodeCategory.ChildNodes.Add(nodeProduct);
				}

				// Keep all categories collapsed (initially).
				nodeCategory.Collapse();
			}
		}
    }
开发者ID:Helen1987,项目名称:edu,代码行数:34,代码来源:TreeViewDB.aspx.cs


示例13: recursiceRemoveSelectedItemImage

 private void recursiceRemoveSelectedItemImage(TreeNode node)
 {
     foreach (TreeNode subnode in node.ChildNodes) {
         subnode.ImageUrl = string.Empty;
         recursiceRemoveSelectedItemImage(subnode);
     }
 }
开发者ID:kyvkri,项目名称:mgone,代码行数:7,代码来源:Default.aspx.cs


示例14: InOrderTraverseLoop

        static void InOrderTraverseLoop(TreeNode<int> root)
        {
            Stack<TreeNode<int>> stack = new Stack<TreeNode<int>>();

            TreeNode<int> cur = root;

            while (cur != null)
            {
                if (cur.Visited == false && cur.Left != null)
                {
                    stack.Push(cur);
                    cur = cur.Left;
                    continue;
                }

                Console.Write(cur.Value);
                Console.Write(" ");

                if (cur.Right != null)
                {
                    cur = cur.Right;
                    continue;
                }

                if (!stack.IsEmpty())
                {
                    cur = stack.Pop();
                    cur.Visited = true;
                }
                else
                    cur = null;
            }
        }
开发者ID:yizhengc,项目名称:MyAlgorithmCode,代码行数:33,代码来源:InOrderTraverse.cs


示例15: BuildTree

    private TreeNode BuildTree()
    {
        this.root = new TreeNode((char)0);
        this.maxTreeDepth = 0;

        for (int stringIndex = 0; stringIndex < this.searchStrings.Length; ++stringIndex)
        {
            string s = this.searchStrings[stringIndex];
            this.maxTreeDepth = Math.Max(this.maxTreeDepth, s.Length);

            var node = this.root;
            for (int charIndex = 0; charIndex < s.Length; ++charIndex)
            {
                char c = s[charIndex];
                TreeNode newNode = node.GetTransition(c);
                if (newNode == null)
                {
                    int terminal = (charIndex == s.Length - 1) ? stringIndex : -1;
                    newNode = node.AddTransition(c, terminal);
                }
                else if (charIndex == s.Length - 1)
                {
                    newNode.Terminal = stringIndex;
                }

                node = newNode;
            }
        }

        ++this.maxTreeDepth;
        return this.root;
    }
开发者ID:Ivan-Dimitrov-bg,项目名称:.Net-framework,代码行数:32,代码来源:AhoCorasickStringSearcher.cs


示例16: MinDepth

    public int MinDepth(TreeNode root)
    {
        int depth = 0;
        Queue<TreeNode> nodes = new Queue<TreeNode>();

        if(root != null)
        {
            nodes.Enqueue(root);
        }

        while(nodes.Count != 0)
        {
            depth++;
            int noNodesInLevel = nodes.Count;
            for(int i = 0; i < noNodesInLevel; i++)
            {
                TreeNode node = nodes.Dequeue();
                if(node.left == null && node.right == null)
                {
                    return depth;
                }
                if(node.left != null)
                {
                    nodes.Enqueue(node.left);
                }
                if(node.right != null)
                {
                    nodes.Enqueue(node.right);
                }
            }
        }

        return depth;
    }
开发者ID:tushar-jaiswal,项目名称:LeetCode,代码行数:34,代码来源:MinDepthBinaryTree.cs


示例17: rSortedListToBST

        public TreeNode rSortedListToBST(ListNode head, int size, out ListNode tail)
        {
            if (size == 1)
            {
                tail = head.next;
                return new TreeNode(head.val);
            }
            else
            {
                int left = size / 2;
                int right = size - 1 - left;

                var ltree = rSortedListToBST(head, left, out tail);

                var root = new TreeNode(tail.val);
                root.left = ltree;

                if (right > 0) {
                    var rtree = rSortedListToBST (tail.next, right, out tail);
                    root.right = rtree;
                } else {
                    tail = tail.next;
                }

                return root;
            }
        }
开发者ID:yizhengc,项目名称:MyCSharpAlgorithms,代码行数:27,代码来源:ListToBST.cs


示例18: FindNode_NodeThere_ReturnsTheNode

		public void FindNode_NodeThere_ReturnsTheNode()
		{
			var node = new TreeNode("AnotherNode");
			service.PushNode(node);
			service.PopNode();
			Assert.AreEqual(node, service.FindNode("AnotherNode"));
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:7,代码来源:DefaultTreeCreationServiceTests.cs


示例19: GetPathWithGivenSum

 public static void GetPathWithGivenSum(TreeNode<int> startupNode, int sum)
 {
     var pathsWithGivenSum = new List<List<int>>();
     var currentPath = new LinkedList<int>();
     ConnectPathsWithGivenSum (startupNode, currentPath, pathsWithGivenSum, sum);
     PrintPathsWithGivenSum(pathsWithGivenSum,sum);
 }
开发者ID:dhristoskov,项目名称:DateStructure,代码行数:7,代码来源:TreeTraverseUtils.cs


示例20: GetHeight

   public override int GetHeight(TreeNode tn)
   {
      if (this.Layout == null)
         return 0;

      return this.Layout.ItemHeight - 4;
   }
开发者ID:Sugz,项目名称:Outliner-3.0,代码行数:7,代码来源:ColorTagButton.cs



注:本文中的TreeNode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TreeNodeAdv类代码示例发布时间:2022-05-24
下一篇:
C# TreeModel类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap