/// <summary> /// 添加节点 /// </summary> internal int AddNode(TreeGridNodeCollection nodes, object info) { var parentId = (int)info.GetValue(nameof(IParent.ParentId)); if (parentId == 0) { return(nodes.Add(info.GetValues()).RowIndex); } for (int i = 0; i < nodes.Count; i++) { if (nodes[i].Cells[IdColumn()].Value.ToInt() == parentId) { if (!nodes[i].IsExpanded) { nodes[i].Expand(); } return(nodes[i].Nodes.Add(info.GetValues()).RowIndex); } if (nodes[i].Nodes.Count > 0) { if (!nodes[i].IsExpanded) { nodes[i].Expand(); } var index = AddNode(nodes[i].Nodes, info); if (index > -1) { return(index); } } } return(-1); }
private void CollapseAll(TreeGridNodeCollection nodes) { for (int i = 0; i < nodes.Count; i++) { if (nodes[i].Nodes.Count > 0) { CollapseAll(nodes[i].Nodes); nodes[i].Collapse(); } } }
private void ExpandAll(TreeGridNodeCollection nodes) { for (int i = 0; i < nodes.Count; i++) { if (nodes[i].Nodes.Count > 0) { nodes[i].Expand(); ExpandAll(nodes[i].Nodes); } } }
/// <summary> /// 删除节点 /// </summary> internal bool DeleteNode(TreeGridNodeCollection nodes, int id) { for (int i = 0; i < nodes.Count; i++) { if (nodes[i].Cells[IdColumn()].Value.ToInt() == id) { nodes.RemoveAt(i); return(true); } if (nodes[i].IsExpanded && nodes[i].Nodes.Count > 0) { if (DeleteNode(nodes[i].Nodes, id)) { return(true); } } } return(false); }
/// <summary> /// 更新节点 /// </summary> internal bool UpdateNode(TreeGridNodeCollection nodes, object info, int id) { for (int i = 0; i < nodes.Count; i++) { if (nodes[i].Cells[IdColumn()].Value.ToInt() == id) { nodes[i].Update(info); return(true); } if (nodes[i].IsExpanded && nodes[i].Nodes.Count > 0) { if (UpdateNode(nodes[i].Nodes, info, id)) { return(true); } } } return(false); }