/// <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 Node Add(string sNodeText) { Node oNode = new Node(); oNode._TreeView = this.ParentTree; oNode.Text = sNodeText; Add(oNode); oNode.SetParent(ParentNode); oNode.TreeView = ParentTree; return oNode; }
public void Insert(int index, Node value) { if (List.Contains(value)) throw new Exception("Node is already in collection."); if (this.ParentNode != null) { // check if the node is not already in the set if (this.ParentNode.TreeView.NodePool.Contains(value) == true) throw new Exception("Node is already in collection."); value.TreeView = ParentNode.TreeView; value.SetParent(ParentNode); } else { if (ParentTree != null) { // check if the node is not already in the set if (ParentTree.NodePool.Contains(value) == true) throw new Exception("Node is already in collection."); value.TreeView = ParentTree; } } List.Insert(index, value); TreeView treeView = null; if (ParentTree != null) treeView = ParentTree; if (ParentNode != null && treeView == null) treeView = ParentNode.TreeView; if (treeView != null) { treeView.NodePool.Add(value); foreach (Node oCollectionNode in this) oCollectionNode.m_nCollectionOrder = oCollectionNode.Index; treeView.Invalidate(); treeView.InvokeNodeAdded(value); } }
/// <summary> /// Creates the new subnode and adds the node to the node collection /// </summary> /// <returns></returns> public Node CreateSubNode() { Node oNode = new Node(); oNode.SetParent(this); Nodes.Add(oNode); return oNode; }