/// <summary> /// /// </summary> public GTree() { _indent = 30; _rootNode = new GTreeNode(true); _rootNode._SetTree(this); _rootNode.expanded = true; }
/// <summary> /// /// </summary> /// <param name="child"></param> /// <param name="index"></param> /// <returns></returns> public GTreeNode AddChildAt(GTreeNode child, int index) { if (child == null) { throw new Exception("child is null"); } int numChildren = _children.Count; if (index >= 0 && index <= numChildren) { if (child.parent == this) { SetChildIndex(child, index); } else { if (child.parent != null) { child.parent.RemoveChild(child); } int cnt = _children.Count; if (index == cnt) { _children.Add(child); } else { _children.Insert(index, child); } child.parent = this; child._level = _level + 1; child._SetTree(this.tree); if (tree != null && this == tree.rootNode || _cell != null && _cell.parent != null && _expanded) { tree._AfterInserted(child); } } return(child); } else { throw new Exception("Invalid child index"); } }
internal void _SetTree(GTree value) { tree = value; if (tree != null && tree.treeNodeWillExpand != null && _expanded) { tree.treeNodeWillExpand(this, true); } if (_children != null) { int cnt = _children.Count; for (int i = 0; i < cnt; i++) { GTreeNode node = _children[i]; node._level = _level + 1; node._SetTree(value); } } }
/// <summary> /// /// </summary> /// <param name="index"></param> /// <returns></returns> public GTreeNode RemoveChildAt(int index) { if (index >= 0 && index < numChildren) { GTreeNode child = _children[index]; _children.RemoveAt(index); child.parent = null; if (tree != null) { child._SetTree(null); tree._AfterRemoved(child); } return(child); } else { throw new Exception("Invalid child index"); } }