System.Web.UI.WebControls.TreeView.FindNode C# (CSharp) Method

FindNode() public method

public FindNode ( string valuePath ) : System.Web.UI.WebControls.TreeNode
valuePath string
return System.Web.UI.WebControls.TreeNode
		public TreeNode FindNode (string valuePath)
		{
			if (valuePath == null)
				throw new ArgumentNullException ("valuePath");
			string[] path = valuePath.Split (PathSeparator);
			int n = 0;
			TreeNodeCollection col = Nodes;
			bool foundBranch = true;
			while (col.Count > 0 && foundBranch) {
				foundBranch = false;
				foreach (TreeNode node in col) {
					if (node.Value == path [n]) {
						if (++n == path.Length)
							return node;
						col = node.ChildNodes;
						foundBranch = true;
						break;
					}
				}
			}
			return null;
		}
		

Usage Example

Exemplo n.º 1
0
        private static void ExpandValuePath(TreeView treeView, string valuePath)
        {
            if (treeView == null) return;
            if (valuePath == null) return;

            if (valuePath.Length > 0)
            {
                TreeNode treeNode;
                treeNode = treeView.FindNode(valuePath);

                if (treeNode != null)
                {
                    if (
                        (treeNode.Expanded == null)
                        || (treeNode.Expanded.Equals(false))
                        )
                    {
                        treeNode.Expand();
                        log.Debug("Expanded treeNode found for value path " + valuePath);
                    }
                }
                else
                {
                    log.Debug(" treeNode was null for " + valuePath);
                }
            }
        }
All Usage Examples Of System.Web.UI.WebControls.TreeView::FindNode