/// <summary> /// Adds the node by the specified path /// </summary> /// <param name="sPath">Path to add</param> /// <param name="bCreateStructure">Specifies wheter to create the structure</param> public Node AddNodeByPath(string sPath, bool bCreateStructure) { // parse the node path for nodes string[] aNodes = GetNodesFromPath(sPath); Node oParent = null; NodeCollection oCollection = this.Nodes; if (bCreateStructure == true) { foreach (string sNode in aNodes) { if (sNode == "") continue; Node oNode = GetCollectionNode(oCollection, sNode); // create the node if (oNode == null && oParent == null) { oNode = new Node(); oNode.Text = sNode; oNode.SetNodeTreeViewReference(this); oCollection.Add(oNode); } if (oNode == null && oParent != null) { oNode = new Node(); oNode.SetNodeTreeViewReference(this); oNode.Text = sNode; oNode.SetParent(oParent); oCollection.Add(oNode); } oCollection = oNode.Nodes; oParent = oNode; } } else { Node oNode = null; for (int nNode = 0; nNode < aNodes.Length - 1; nNode ++) { string sNode = aNodes[nNode]; oNode = GetCollectionNode(oCollection, sNode); if (oNode == null) return null; oCollection = oNode.Nodes; } if (oNode == null) return null; Node oSubNode = oNode.CreateSubNode(); oSubNode.SetNodeTreeViewReference(this); oSubNode.Text = aNodes[aNodes.Length - 1]; oSubNode.Parent = oNode; return oNode; } return oParent; }
public int Add(Node value) { TreeView treeView = null; if (ParentTree != null) treeView = ParentTree; if (ParentNode != null && treeView == null) treeView = ParentNode.TreeView; if (List.Contains(value)) return List.IndexOf(value); if (treeView != null && treeView.NodePool.Contains(value) == true) throw new Exception("Node is already added in other nodes collection."); value.SetNodeTreeViewReference(treeView); int nPos = List.Add(value); if (treeView != null) { treeView.NodePool.Add(value); treeView.InvokeNodeAdded(value); } return nPos; }