private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode) { XmlNode xNode; TreeNode tNode; XmlNodeList nodeList; int i; // Loop through the XML nodes until the leaf is reached. // Add the nodes to the TreeView during the looping process. if (inXmlNode.HasChildNodes && inXmlNode.FirstChild.HasChildNodes) { nodeList = inXmlNode.ChildNodes; for (i = 0; i <= nodeList.Count - 1; i++) { xNode = inXmlNode.ChildNodes[i]; inTreeNode.Nodes.Add(xNode.Name, xNode.Name); tNode = inTreeNode.Nodes[i]; AddNode(xNode, tNode); } } else { // Here you need to pull the data from the XmlNode based on the // type of node, whether attribute values are required, and so forth. String str = (inXmlNode.InnerText).Trim(); TreeNode parent = inTreeNode.Parent; inTreeNode.Remove(); parent.Nodes.Add(str, str); //inTreeNode.Text = (inXmlNode.InnerText).Trim(); } }
private bool RecursiveTextSearchAndDestroy(TreeNode treeNode, string target) { bool flag1 = false; if (treeNode.Text == target) { bool flag2 = true; m_recursiveDestroy = true; return flag2; } else { foreach (TreeNode treeNode1 in treeNode.Nodes) { if (treeNode1 != null) { flag1 = RecursiveTextSearchAndDestroy(treeNode1, target); if (flag1 && m_recursiveDestroy) { treeNode.Remove(); m_recursiveDestroy = false; break; } } } return flag1; } }
/// <summary> /// Moves the selected item one level to the left. /// </summary> /// <param name="sender">Source object</param> /// <param name="e">Event arguments</param> private void LeftButton_click(object sender, EventArgs e) { System.Windows.Forms.TreeNodeCollection col; Microsoft.Web.UI.WebControls.TreeNodeCollection webCol; System.Windows.Forms.TreeNode movingNode = SelectedNode; System.Windows.Forms.TreeNode parentnode = movingNode.Parent; if (parentnode.Parent != null) { col = parentnode.Parent.Nodes; webCol = ((Microsoft.Web.UI.WebControls.TreeNode)((Microsoft.Web.UI.WebControls.TreeNode)parentnode.Tag).Parent).Nodes; } else { col = tvNodes.Nodes; webCol = tvWebNodes.Nodes; } ((Microsoft.Web.UI.WebControls.TreeNode)movingNode.Tag).Remove(); movingNode.Remove(); col.Insert(parentnode.Index + 1, movingNode); webCol.AddAt(movingNode.Index, ((Microsoft.Web.UI.WebControls.TreeNode)movingNode.Tag)); SelectedNode = movingNode; btnApply.Enabled = true; }
private void OnRemoveButtonClick() { this.ValidatePropertyGrid(); System.Windows.Forms.TreeNode selectedNode = this._treeView.SelectedNode; if (selectedNode != null) { System.Windows.Forms.TreeNodeCollection nodes = null; if (selectedNode.Parent != null) { nodes = selectedNode.Parent.Nodes; } else { nodes = this._treeView.Nodes; } if (nodes.Count == 1) { this._treeView.SelectedNode = selectedNode.Parent; } else if (selectedNode.NextNode != null) { this._treeView.SelectedNode = selectedNode.NextNode; } else { this._treeView.SelectedNode = selectedNode.PrevNode; } selectedNode.Remove(); if (this._treeView.SelectedNode == null) { this._propertyGrid.SelectedObject = null; } this.UpdateEnabledState(); } }
public void ChangeAccountSettings(TreeNode thisNode, string accountEndpoint) { this.treeView1.SelectedNode = thisNode; for (int i = 0; i < Settings.Default.AccountSettingsList.Count; i = i + 2) { if (string.Compare(accountEndpoint, Properties.Settings.Default.AccountSettingsList[i], StringComparison.OrdinalIgnoreCase) == 0) { AccountSettings accountSettings = (AccountSettings)JsonConvert.DeserializeObject(Settings.Default.AccountSettingsList[i + 1], typeof(AccountSettings)); // Bring up account setings dialog SettingsForm dlg = new SettingsForm(); dlg.AccountEndpoint = accountEndpoint; dlg.AccountSettings = accountSettings; DialogResult dr = dlg.ShowDialog(this); if (dr == DialogResult.OK) { thisNode.Remove(); RemoveAccountFromSettings(dlg.AccountEndpoint); AddAccountToSettings(dlg.AccountEndpoint, dlg.AccountSettings); } break; } } }
/// <summary> /// 递归删除节点 /// </summary> /// <param name="treeNode"></param> private void DeleteTreeNodeAndDataInDB(TreeNode treeNode) { string sql = "delete TblArea where AreaId="; while (treeNode.Nodes.Count != 0) { DeleteTreeNodeAndDataInDB(treeNode.Nodes[0]); } treeNode.Remove(); SqlHelper.ExecuteNonQuery(sql + treeNode.Tag.ToString(), CommandType.Text); }
public void RemoveChild(TreeNode node) { if (node.TreeView != this) { throw new Exception("The node doesn't belong to this TreeView"); } TreeNode parent = node.Parent; node.Remove(); UpdateParent(parent); }
public static void UpdateTeeViewNode(AccountFileStates newFileState, TreeNode node) { if ((newFileState & AccountFileStates.Deleted) != 0) { node.Remove(); return; } if ((newFileState & AccountFileStates.New) != 0) { node.ForeColor = Color.Green; } }
private void PasteAction(TreeNode source, TreeNode dest) { if (dest != source && (!IsChildNode(source, dest) || dest == null)) { var gc = (GroupComposite) ((Composite) source.Tag).Parent; if ((_copyAction & CopyPasteOperactions.Copy) != CopyPasteOperactions.Copy) gc.Children.Remove((Composite) source.Tag); AddToActionTree(source, dest); if ((_copyAction & CopyPasteOperactions.Copy) != CopyPasteOperactions.Copy) // ctrl key source.Remove(); _copySource = null; // free any ref.. } }
private void OnIndentButtonClick() { System.Windows.Forms.TreeNode selectedNode = this._treeView.SelectedNode; if (selectedNode != null) { System.Windows.Forms.TreeNode prevNode = selectedNode.PrevNode; if (prevNode != null) { selectedNode.Remove(); prevNode.Nodes.Add(selectedNode); this._treeView.SelectedNode = selectedNode; } } }
/// <summary> /// Moves the selected item one level to the right. /// </summary> /// <param name="sender">Source object</param> /// <param name="e">Event arguments</param> private void RightButton_click(object sender, EventArgs e) { System.Windows.Forms.TreeNodeCollection col; Microsoft.Web.UI.WebControls.TreeNodeCollection webCol; System.Windows.Forms.TreeNode movingNode = SelectedNode; System.Windows.Forms.TreeNode prevnode = movingNode.PrevNode; ((Microsoft.Web.UI.WebControls.TreeNode)movingNode.Tag).Remove(); col = prevnode.Nodes; webCol = ((Microsoft.Web.UI.WebControls.TreeNode)prevnode.Tag).Nodes; movingNode.Remove(); col.Add(movingNode); webCol.Add(((Microsoft.Web.UI.WebControls.TreeNode)movingNode.Tag)); SelectedNode = movingNode; btnApply.Enabled = true; }
private void OnMoveUpButtonClick() { System.Windows.Forms.TreeNode selectedNode = this._treeView.SelectedNode; if (selectedNode != null) { System.Windows.Forms.TreeNode prevNode = selectedNode.PrevNode; System.Windows.Forms.TreeNodeCollection nodes = this._treeView.Nodes; if (selectedNode.Parent != null) { nodes = selectedNode.Parent.Nodes; } if (prevNode != null) { selectedNode.Remove(); nodes.Insert(prevNode.Index, selectedNode); this._treeView.SelectedNode = selectedNode; } } }
private void OnMoveDownButtonClick() { this.ValidatePropertyGrid(); System.Windows.Forms.TreeNode selectedNode = this._treeView.SelectedNode; if (selectedNode != null) { System.Windows.Forms.TreeNode nextNode = selectedNode.NextNode; System.Windows.Forms.TreeNodeCollection nodes = this._treeView.Nodes; if (selectedNode.Parent != null) { nodes = selectedNode.Parent.Nodes; } if (nextNode != null) { selectedNode.Remove(); nodes.Insert(nextNode.Index + 1, selectedNode); this._treeView.SelectedNode = selectedNode; } } }
private void OnUnindentButtonClick() { System.Windows.Forms.TreeNode selectedNode = this._treeView.SelectedNode; if (selectedNode != null) { System.Windows.Forms.TreeNode parent = selectedNode.Parent; if (parent != null) { System.Windows.Forms.TreeNodeCollection nodes = this._treeView.Nodes; if (parent.Parent != null) { nodes = parent.Parent.Nodes; } if (parent != null) { selectedNode.Remove(); nodes.Insert(parent.Index + 1, selectedNode); this._treeView.SelectedNode = selectedNode; } } } }
private void SetupNode(TreeNode node) { // Remove it from any old parents node.Remove(); node.parent = owner; TreeView tree_view = null; if (owner != null) { tree_view = owner.TreeView; } if (tree_view != null) { TreeNode prev = GetPrevNode(node); if (tree_view.IsHandleCreated && node.ArePreviousNodesExpanded) { tree_view.RecalculateVisibleOrder(prev); } if (owner == tree_view.root_node || node.Parent.IsVisible && node.Parent.IsExpanded) { tree_view.UpdateScrollBars(false); } } if (owner != null && tree_view != null && (owner.IsExpanded || owner.IsRoot)) { tree_view.UpdateBelow(owner); } else if (owner != null && tree_view != null) { tree_view.UpdateBelow(owner); } }
private int AddInternal(TreeNode node, int delta) { if (node == null) { throw new ArgumentNullException("node"); } if (node.parent != null) { node.Remove(); } node.parent = owner; node.index = items.Count; items.Add(node); if (owner.TreeView != null) { node.treeView = owner.TreeView; } return(node.index); }
public virtual int Add(TreeNode node) { if (node == null) { throw new ArgumentNullException("node"); } if (node.parent != null) { node.Remove(); } node.parent = owner; node.index = items.Count; items.Add(node); if (owner.TreeView != null) { node.treeView = owner.TreeView; } return(node.index); }
/// <summary> /// 删除脚本文件夹 /// </summary> /// <param name="folderNode">脚本文件夹树结点</param> /// <return>是否删除成功</return> private bool DeleteScriptFolder(TreeNode folderNode) { List<TreeNode> childNodeList = new List<TreeNode>(); foreach (TreeNode childNode in folderNode.Nodes) { childNodeList.Add(childNode); } foreach (TreeNode childNode in childNodeList) { Hashtable infoTable = childNode.Tag as Hashtable; if (infoTable["type"] as string == "folder") { DeleteScriptFolder(childNode); } else if (infoTable["type"] as string == "file") { DeleteScriptFile(childNode); } } folderNode.Remove(); return true; }
private void OnTreeNodeRemove( TreeNode tnChild ) { tnChild.Remove(); }
public void MoveNode(TreeNode what, TreeNode where, NodeRelationship relation, NodeRelationship subRelation = NodeRelationship.Null, bool suspendUpdate = false) { if (!IsAllowedToHaveRelation(where,what,relation)) return; if (subRelation == NodeRelationship.Null) subRelation = Settings.Current.DragIntoFolderToLastPosition ? NodeRelationship.ChildGoesUnder : NodeRelationship.ChildGoesAbove; TreeNode result = null; if (!suspendUpdate) BeginUpdate(); if (where == null) { what.Remove(); Nodes.Add(what); } else { if (what != where) switch (relation) { case NodeRelationship.ChildGoesAbove: what.Remove(); if (where.Parent != null) where.Parent.Nodes.Insert(where.Index, what); else Nodes.Insert(where.Index, what); result = what; break; case NodeRelationship.ChildGoesInside: what.Remove(); if (subRelation == NodeRelationship.ChildGoesUnder) where.Nodes.Add(what); if (subRelation == NodeRelationship.ChildGoesAbove) where.Nodes.Insert(0, what); result = what; break; case NodeRelationship.ChildGoesUnder: what.Remove(); if (where.Parent != null) where.Parent.Nodes.Insert(where.Index + 1, what); else Nodes.Insert(where.Index + 1, what); result = what; break; } } if (result!=null) SelectedNode = result; if (!suspendUpdate) EndUpdate(); OnNodeMoved(result, suspendUpdate); }
private void DeleteItem(TreeNode node) { if (node == null) return; InventoryBase io = (InventoryBase)node.Tag; if (io is InventoryFolder) { InventoryFolder folder = (InventoryFolder)io; treeLookup.Remove(folder.UUID); client.Inventory.RemoveFolder(folder.UUID); folder = null; } else if (io is InventoryItem) { InventoryItem item = (InventoryItem)io; treeLookup.Remove(item.UUID); client.Inventory.RemoveItem(item.UUID); item = null; } io = null; node.Remove(); node = null; }
/// <summary> /// Remove one TreeNode. The TreeNode is also removed from the SelNodes property, the CheckedNodes property and/or the SelNode property. /// </summary> /// <param name="tn">TreeNode to remove.</param> /// <returns>True if the TreeNode was removed or false otherwise.</returns> public bool RemoveNode(TreeNode tn) { bool bRetVal = false; if(tn != null) { DeleteNode(tn); try { tn.Remove(); if(tn.TreeView == null && !IsTreeNodeSelected(tn) && !IsTreeNodeChecked(tn) && tn != this.SelNode) { bRetVal = true; } } catch { } } return bRetVal; }
/// <include file='doc\TreeNodeCollection.uex' path='docs/doc[@for="TreeNodeCollection.Remove"]/*' /> public void Remove(TreeNode node) { node.Remove(); }
public void RemoveNode(TreeNode node) { if (node != null && node.Parent != null) { (node.Tag as Node).Parent.Remove(node.Tag as Node); node.Remove(); } }
void MoveNode( TreeNode position, TreeNode source ) { if ( ParentContainer( source, position ) || position == source ) return; if ( position.Tag is string && !Directory.Exists( position.Tag as string ) ) { if ( source.Tag is string ) { string newtag = ToRightPath( GetNodePath( position.Parent ) + source.Text ); File.Move( source.Tag as string, newtag ); source.Tag = newtag; source.Remove( ); position.Parent.Nodes.Insert( 0, source ); } else { ChangeTags( source, GetNodePath( source ), ToRightPath( GetNodePath( position.Parent ) + source.Text ) ); Directory.Move( GetNodePath( source ), ToRightPath( GetNodePath( position.Parent ) + source.Text ) ); source.Remove( ); position.Parent.Nodes.Insert( 0, source ); } return; } else { if ( source.Tag is string ) { string newtag = ToRightPath( GetNodePath( position ) + source.Text ); File.Move( source.Tag as string, newtag ); source.Tag = newtag; source.Remove( ); position.Nodes.Insert( 0, source ); } else { ChangeTags( source, GetNodePath( source ), ToRightPath( GetNodePath( position ) + source.Text ) ); Directory.Move( GetNodePath( source ), ToRightPath( GetNodePath( position ) + source.Text ) ); source.Remove( ); position.Nodes.Insert( 0, source ); } return; } }
private void FixAnim(TreeNode node) { int itemId = (int)node.Tag; Animdata.Data data = (Animdata.Data)Animdata.AnimData[itemId]; if (data != null) { bool nodefixed = false; for (int i = 0; i < data.FrameCount; ++i) { int itemid = itemId + selData.FrameData[i]; if ((TileData.ItemTable[itemid].Flags & TileFlag.Animation) == 0) { TileData.ItemTable[itemid].Flags |= TileFlag.Animation; nodefixed = true; } } if (nodefixed) { Options.ChangedUltimaClass["TileData"] = true; node.ForeColor = Color.Black; } } if (!Art.IsValidStatic(itemId)) { TileData.ItemTable[itemId].Flags ^= TileFlag.Animation; Options.ChangedUltimaClass["TileData"] = true; Animdata.AnimData.Remove(itemId); Options.ChangedUltimaClass["Animdata"] = true; node.Remove(); } }
private void ClearBotNode(TreeNode node) { Bots.BotRow bot = node.Tag as Bots.BotRow; if (bot != null) { node.Remove(); } else { foreach (TreeNode child in node.Nodes) { ClearBotNode(child); } } }
internal static void DeleteNode(TreeNode node) { TreeNode baseNode = BaseNode(node); // Can only delete internal NBT nodes if (baseNode == null || baseNode == node) return; (baseNode.Tag as DataNode).Modified = true; DeleteNodeNbtTag(node); if (node.Parent != null) { node.Parent.Text = GetNodeText(node.Parent); } node.Remove(); }
/// <summary> /// Remove the children of a folder node from the project. /// </summary> /// <param name="node">The parent folder node</param> /// <param name="permanently">True to delete the items or false /// to just remove them from the project.</param> public void RemoveNode(TreeNode node, bool permanently) { NodeData nodeData; FileItem fileItem; TreeNode[] children; string projectFolder; try { Cursor.Current = Cursors.WaitCursor; treeView.SuspendLayout(); // Remove any children if(node.Nodes.Count > 0) { children = new TreeNode[node.Nodes.Count]; node.Nodes.CopyTo(children, 0); foreach(TreeNode n in children) this.RemoveNode(n, permanently); } // Remove the node itself nodeData = (NodeData)node.Tag; fileItem = (FileItem)nodeData.Item; projectFolder = Path.GetDirectoryName( fileItem.ProjectElement.Project.Filename); fileItem.ProjectElement.RemoveFromProjectFile(); node.Remove(); if(permanently) if(fileItem.BuildAction == BuildAction.Folder) { // If in or below the folder to remove, get out of it if(FolderPath.TerminatePath( Directory.GetCurrentDirectory()).StartsWith( fileItem.Include, StringComparison.OrdinalIgnoreCase)) Directory.SetCurrentDirectory(projectFolder); if(Directory.Exists(fileItem.Include)) Directory.Delete(fileItem.Include, true); } else if(File.Exists(fileItem.Include)) File.Delete(fileItem.Include); } finally { Cursor.Current = Cursors.Default; treeView.ResumeLayout(); } }
public TreeNode MoveTreeNode(LuaTable CatSeq, ref TreeNode node) { int level = -1; TreeNodeCollection nodes = this.baseTree.Nodes; for (int i = 0; i < CatSeq.Values.Count; i++) { foreach (TreeNode eachnode in nodes) { object[] eachNodeTags = eachnode.Tag as object[]; object[] checkNodeTags = CatSeq[i] as object[]; if (eachNodeTags != null && checkNodeTags != null) // 如果待检查的是数组 { bool bSame = true; for (int j = 0; j < eachNodeTags.Length; j++) { if (eachNodeTags[j].ToString().Trim() != checkNodeTags[j].ToString().Trim()) { bSame = false; break; } } if (bSame) { nodes = eachnode.Nodes; level = eachnode.Level; break; } } else if (eachnode.Tag.ToString().Trim() == CatSeq[i].ToString().Trim()) { nodes = eachnode.Nodes; level = eachnode.Level; break; } } } if (level == node.Level - 1) // 精确找到要添加的父亲,添加在此结点下 { TreeNode newnode = (TreeNode)node.Clone(); nodes.Add(newnode); node.Remove(); return newnode; } else if (level == node.Level - 2) // 未精确找到,添加在最后找到的结点的第一个儿子下. { TreeNode newnode = (TreeNode)node.Clone(); nodes[0].Nodes.Add(newnode); node.Remove(); return newnode; } return null; }
/// <summary> /// Method for delete the tree nodes recursively. /// </summary> /// <param name="node">The tree node for delete.</param> public void DeleteNodesRecursive(TreeNode node) { foreach (TreeNode child in node.Nodes) { this.DeleteNodesRecursive(child); } Facade facade = Facade.GetInstance(); MessageStore messageStore = facade.GetMessageStoreCustom(); for (int i = 0; i < messageStore.Messages.Count; i++) { MailMessage mail = messageStore.Messages[i]; if (mail.ParentFolder.Equals(node.Text)) { messageStore.Messages.Remove(mail); } } node.Remove(); }
/// <summary> /// 删除脚本文件 /// </summary> /// <param name="scriptNode">脚本文件树结点</param> /// <returns>是否删除成功</returns> private bool DeleteScriptFile(TreeNode fileNode) { bool deleteSuccess = false; Hashtable infoTable = fileNode.Tag as Hashtable; string id = infoTable["id"].ToString(); DataBaseManager dataBaseManager = DataBaseManager.GetDataBaseManager(); if (!dataBaseManager.IsScriptLocked(id)) { if (dataBaseManager.DeleteScriptData(id)) // 现在数据库里删除 { fileNode.Remove(); // 修改成功,更新树缓存 treePh.Tag = dataBaseManager.GetScriptInformation(); } } else { MessageBox.Show("该脚本已被锁定,无法删除!", "删除脚本", MessageBoxButtons.OK, MessageBoxIcon.Information); } return deleteSuccess; }
private void RemoveTreeNode(TreeNode node) { if (node == null) return; //A headding if (node.Parent == null && openProjectDir != null) return; //A project if (node.Tag is DirectoryInfo) { if (openProjectDir == null) { if (MessageBox.Show(this, LocRM.GetString("Text8.Text ") + node.Text + LocRM.GetString("Text9.Text"), LocRM.GetString("Text10.Text"), MessageBoxButtons.YesNo) == DialogResult.No) return; DirectoryInfo dir = (DirectoryInfo)node.Tag; //dir.Delete(true); DeleteDir(dir.FullName); node.Remove(); return; } } if (node.Tag is FolderItem) {//Folder if (MessageBox.Show(this, LocRM.GetString("Text11.Text") + node.Text + LocRM.GetString("Text12.Text"), LocRM.GetString("Text13.Text"), MessageBoxButtons.YesNo) == DialogResult.No) return; FolderItem folderItem = (FolderItem) node.Tag; //If the deleted file was open, close it. //RecursivlyCloseOpenFiles(folderItem); folderItem.Delete(); //folderItem.Dir.Delete(true); //folderItem.Parent.Children.Remove(folderItem); //folderItem.Parent = null; //folderItem.GUINode.Remove(); //ProjectProperties.CurrentProjectPropperties.Save(); UploadedChangesToMap = false; UploadToMap(); return; } //File if (node.Tag is FileItem) { FileItem file = (FileItem)node.Tag; if (MessageBox.Show(this, LocRM.GetString("Text14.Text") + node.Text + LocRM.GetString("Text15.Text"), LocRM.GetString("Text16.Text"), MessageBoxButtons.YesNo) == DialogResult.No) return; //If the deleted file was open, close it. //RecursivlyCloseOpenFiles(file); //compiler.RemoveSourceFile(file); file.Delete(); //file.File.Delete(); //file.Parent.Children.Remove(file); //file.Parent = null; //ProjectProperties.CurrentProjectPropperties.Save(); //node.Remove(); UploadedChangesToMap = false; UploadToMap(); return; } if (node.Tag is Library) { Library lib = (Library) node.Tag; ProjectProperties.CurrentProjectPropperties.Libraries.Remove(lib); node.Remove(); } if (node.Tag is Library.Item) { MessageBox.Show(this, LocRM.GetString("Text17.Text"), LocRM.GetString("Error.Text")); } if (node.Tag is DialogItem && node == ((DialogItem)node.Tag).GUINode) { DialogItem file = (DialogItem)node.Tag; if (MessageBox.Show(this, LocRM.GetString("Text18.Text") + node.Text + LocRM.GetString("Text19.Text"), LocRM.GetString("Text16.Text"), MessageBoxButtons.YesNo) == DialogResult.No) return; //If the deleted file was open, close it. //RecursivlyCloseOpenFiles(file); //compiler.RemoveSourceFile(file); if (file.OpenFileData != null) { bool b; if (file.OpenFileData.TabPage != null) CloseFile(file.OpenFileData, file.OpenFileData.TabPage, out b, true); if (file.OpenFileData != null && file.OpenFileData.CodeTabPage != null) CloseFile(file.OpenFileData, file.OpenFileData.CodeTabPage, out b, true); if (file.OpenFileData != null && file.OpenFileData.DesignerTabPage != null) CloseFile(file.OpenFileData, file.OpenFileData.DesignerTabPage, out b, true); } file.Delete(); UploadedChangesToMap = false; UploadToMap(); } }
void removeNode(TreeNode node) { InventoryBase item = (InventoryBase)node.Tag; if (item != null) { foreach (TreeNode child in node.Nodes) { removeNode(child); } lock (UUID2NodeCache) { UUID2NodeCache.Remove(item.UUID); } } node.Remove(); }
/// <summary> /// 移动一个节点,并使其可见 /// </summary> /// <param name="treeView"></param> /// <param name="text"></param> /// <param name="tag"></param> public static void MoveTreeNode(TreeView treeView, TreeNode selectNode, TreeNode parentNode) { TreeNode temNode = selectNode; // 2012.05.28 Pcsky加入判断,修正移动最底层叶节点报错(未将对象引用设置到对象的实例)的BUG if (selectNode != null) { // 先删除 selectNode.Remove(); if (parentNode != null) { // 添加到新的父节点下 parentNode.Nodes.Add(temNode); // 展开新的父节点,是新增节点可见 parentNode.Expand(); treeView.SelectedNode = parentNode; } else { treeView.Nodes.Add(temNode); temNode.Expand(); treeView.SelectedNode = temNode; } temNode.EnsureVisible(); } }
private void DeleteMetaFile(TreeNode metaFileNode) { if (metaFileNode.Text == "<пусто>") { return; } string currentMetaFilePath = GetNodePath(metaFileNode); if (currentMetaFilePath == "/") { MessageBox.Show(this, "Невозможно удалить корневой каталог!", "Невозможно удалить", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (currentMetaFilePath.StartsWith(DehaxOS.SYSTEM_DIRECTORY_PATH)) { MessageBox.Show(this, "Невозможно удалить файлы системы!", "Невозможно удалить", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { if (metaFileNode.GetNodeCount(true) > 0) { _dehaxOS.DeleteDirectory(currentMetaFilePath); } else { _dehaxOS.DeleteFile(currentMetaFilePath); } TreeNode parentNode = metaFileNode.Parent; metaFileNode.Remove(); if (parentNode.GetNodeCount(true) == 0) { parentNode.Nodes.Add("<пусто>"); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void DeleteNode(TreeNode node) { if (node == null || !(node.Tag is DataNode)) return; DataNode dataNode = node.Tag as DataNode; if (!dataNode.CanDeleteNode) return; if (dataNode.DeleteNode()) { UpdateUI(node.Parent.Tag as DataNode); UpdateNodeText(node.Parent); node.Remove(); } }
public void RemoveTreeNode(ref TreeNode node) { node.Remove(); }
private void UpdateTreeView(TreeNode node, string functions) { if(node.Parent == null) { if(node.NextNode != null) { UpdateTreeView(node.NextNode, functions); } UpdateTreeView(node.FirstNode, functions); if(node.Nodes.Count == 0) { node.Remove(); } } else { if(node.NextNode != null) { UpdateTreeView(node.NextNode, functions); } if (functions.IndexOf(node.Text) == -1) { node.Remove(); } else { return; } } }
/// <summary> /// Cuts the selected TreeNode /// </summary> /// <param name="node">Selected TreeNode</param> internal void Cut(TreeNode node) { Copy(node, true); node.Remove(); }
private bool MoveNode(TreeNode nodeToMove, TreeNode destination, bool linking) { bool result = false; if (destination == null) { if (_showTreeFaults) { MessageBox.Show(this, "The destination node cannot be null.", "Drag Fault", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign); } if (_throwTreeFaults) { throw new InvalidOperationException("The destination node cannot be null."); } return result; } if (HasAnsester(destination, nodeToMove)) { if (_showTreeFaults) { MessageBox.Show(this, "The destination node cannot be parented by the node been dragged.", "Drag Fault", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign); } if (_throwTreeFaults) { throw new InvalidOperationException( "The destination node cannot be parented by the node been dragged."); } return result; } if (nodeToMove == destination) { return result; } //if (destination != null) //{ TreeNode clonedNode = (TreeNode) nodeToMove.Clone(); clonedNode.Tag = nodeToMove.Tag; clonedNode.Checked = false; destination.Nodes.Add(clonedNode); if (linking == false) { nodeToMove.Remove(); } clonedNode.EnsureVisible(); clonedNode.TreeView.SelectedNode = clonedNode; result = true; //} return result; }