/// <summary> /// 初始化结构体,默认current_nodes=null /// </summary> public void init() { current_nodes_name = null; current_nodes_text = null; current_node_lujing = null; current_multtreenode = null; }
/// <summary> /// 通过TreeViewData弹出TreeView /// </summary> /// <param name="IMult"></param> public void PopulateTree(IMultTreeNode IMult) { if (this.Nodes == null || this.Nodes.Length == 0) { return;//判断节点数组是否为空或没有节点 } #region 无用代码 // treeview.BeginUpdate();//禁止树视图重绘 #endregion for (int i = 0; i <= this.Nodes.Length - 1; i++) { #region 无用代码 #region 无用代码 // treeview.Nodes.Add(this.Nodes[i].ToTreeNode());//把节点添加到树中 //MultTreeNode tr = new MultTreeNode(); //tr.setSelfId(this.Nodes[i].ToTreeNode().getSelfId()); //tr.setNodeName( this.Nodes[i].ToTreeNode().getNodeName()); //tr.setParent(this.Nodes[i].ToTreeNode().getParentId()); //tr.setParentNode(this.Nodes[i].ToTreeNode().getParentNode()); //tr.setChildList(this.Nodes[i].ToTreeNode().getChildList()); // treeview.Nodes.Add(tr); //MachineVision.ShuJuJieGou.TreeStatic.get_Root().getChildList().Add(this.Nodes[i].ToTreeNode()); #endregion // IMult.getChildList().Add(this.Nodes[i].ToTreeNode()); #endregion IMult.InsertChildNode(this.Nodes[i].ToTreeNode()); } #region 无用代码 // treeview.EndUpdate();//启动树视图重绘 #endregion }
/// <summary> /// 删除当前节点和他的晚辈 /// </summary> public void deleteNode() { IMultTreeNode parentNode = this.ParentNode; string id = this.SelfId; if (parentNode != null) { parentNode.deleteChildNode(id); } }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="_IMult"></param> static void SaveTreeViewData(string path, IMultTreeNode _IMult) { BinaryFormatter ser = new BinaryFormatter(); Stream file = new FileStream(path, FileMode.Create); #region 无用代码 // ser.Serialize(file, new TreeViewData(TreeStatic.get_Root())); #endregion ser.Serialize(file, new TreeViewData(_IMult)); file.Close(); }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="_IMult"></param> static void LoadTreeViewData(string path, IMultTreeNode _IMult) { #region 无用代码 // TreeStatic.get_Root().getChildList().Clear();//加载时先清空跟节点的子节点 #endregion _IMult.getChildList().Clear();//加载时先清空跟节点的子节点 BinaryFormatter ser = new BinaryFormatter(); Stream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); TreeViewData treeData = ((TreeViewData)(ser.Deserialize(file))); treeData.PopulateTree(_IMult); file.Close(); }
/// <summary> /// 递归初始化TreeView数据 /// </summary> /// <param name="Mtr"></param> public TreeViewData(IMultTreeNode Mtr) { Nodes = new TreeNodeData[Mtr.getChildNodeCount()];//获取树节点数 创建对应个数的TreeNodeData数组 if (Mtr.getChildNodeCount() == 0) { return;//等于O就返回 } for (int i = 0; i <= Mtr.getChildNodeCount() - 1; i++) { // Nodes[i] = new TreeNodeData(treeview.Nodes[i]);//把节点对应添加到数组中 Nodes[i] = new TreeNodeData(Mtr.getChildList()[i]); } }
/// <summary> /// 初始化树 /// </summary> public static void initTreeView(TreeView treeView_, IMultTreeNode root_) { TreeNode tr_0 = new TreeNode(); tr_0.Text = "驱动1"; tr_0.Name = "System_1"; //新建一个驱动 if (treeView_.Nodes != null) { treeView_.Nodes.Clear(); }//清空树 TreeStatic.load_MultTreeNode_To_TreeNode_ContainsSelf(tr_0, root_); treeView_.Nodes.Add(tr_0);//添加一个检测 treeView_.ExpandAll(); }
/// <summary> /// 把MultTreeNode节点添加到treeview节点,包含他自己,跟子节点 /// </summary> /// <param name="tr"></param> /// <param name="mtr"></param> /// <returns></returns> public static bool load_MultTreeNode_To_TreeNode_ContainsSelf(TreeNode tr, IMultTreeNode mtr) { bool ok = false; TreeNode tr_1 = new TreeNode(); //tr_1.Text = mtr.getNodeName(); //tr_1.Name = mtr.getSelfId(); tr_1.Text = mtr.NodeName; tr_1.Name = mtr.SelfId; tr.Nodes.Add(tr_1); if (!mtr.isLeaf()) { load_MultTreeNode_To_TreeNode(tr_1, mtr); } ok = true; return(ok); }
/// <summary> /// 判断节点路径是否存在 /// </summary> /// <param name="jieDianLuJing"></param> /// <returns></returns> public static bool PanDuanFuJieDianShiFoCunZai(string jieDianLuJing) { bool ok = false; string[] str_Jie = jieDianLuJing.Split('>'); IMultTreeNode mu_ = MultTree.TreeStatic.Root; bool run = true; for (int i = 0; i < str_Jie.Length && run == true; i++) { mu_ = mu_.findNodeById(str_Jie[i]); if (mu_ == null) { run = false; } } if (run == true) { ok = true; } return(ok); }
/// <summary> /// 把MultTreeNode节点的子节点添加到treeview节点 /// </summary> /// <param name="tr">传入</param> /// <param name="mtr">传入</param> /// <returns></returns> public static bool load_MultTreeNode_To_TreeNode(TreeNode tr, IMultTreeNode mtr) { bool ok = false; foreach (MultTreeNode mtr_ in mtr.getChildList()) { TreeNode tr_1 = new TreeNode(); #region 无用代码 //tr_1.Text = mtr_.getNodeName(); //tr_1.Name = mtr_.getSelfId(); #endregion tr_1.Text = mtr_.NodeName; tr_1.Name = mtr_.SelfId; tr.Nodes.Add(tr_1); if (!mtr_.isLeaf()) { load_MultTreeNode_To_TreeNode(tr_1, mtr_); } } ok = true; return(ok); }
/// <summary> /// 构造函数 /// </summary> /// <param name="Mult">传入要处理的节点</param> public TreeViewDataAccess(IMultTreeNode Mult) { _IMult = Mult; }