public void RemoveNodeTest2() { var parent = new TreeNode <String>(); var target = new TreeNodeCollection <String>(parent); var item = new TreeNode <String>(); target.Add(item); var item1 = new TreeNode <String>(); target.Add(item1); var result = target.Remove(item, false); Assert.True(result); Assert.Same(parent, item.Parent); Assert.False(target.Contains(item)); result = target.Remove(item1, false); Assert.True(result); Assert.Same(parent, item1.Parent); Assert.False(target.Contains(item1)); Assert.Equal(0, target.Count); }
public void TreeNodeCollection_Method_Contains() { TreeNodeCollection tnc = new TreeNodeCollection(); TreeNode tn = new TreeNode("TreeNodeName"); tnc.Add(new TreeNode()); Assert.AreEqual(false, tnc.Contains(tn), "BeforeContains"); tnc.Add(tn); tnc.Add(new TreeNode()); Assert.AreEqual(true, tnc.Contains(tn), "AfterContains"); }
public void RemoveNodeTest2() { var parent = new TreeNode <String>(); var target = new TreeNodeCollection <String>(parent); var item = new TreeNode <String>(); target.Add(item); var item1 = new TreeNode <String>(); target.Add(item1); var result = target.Remove(item, false); Assert.True(result); Assert.Same(parent, item.Parent); #pragma warning disable xUnit2017 Assert.False(target.Contains(item)); #pragma warning restore xUnit2017 result = target.Remove(item1, false); Assert.True(result); Assert.Same(parent, item1.Parent); Assert.DoesNotContain(item1, target); Assert.Empty(target); }
public static TreeNode FindPrevNode(TreeNodeCollection nodes, TreeNode selected) { if (nodes != null && nodes.Count > 0) { TreeNode node1 = (selected == null) ? nodes[0] : selected; TreeNode backup = node1; if (node1.Parent == null || nodes.Contains(node1) == true) { // if we not on first node if (node1.Index > 0 && node1.Index < nodes.Count) { TreeNode node2 = nodes[node1.Index - 1]; node1 = node2; // find last child of new selected node if (node2.Nodes.Count > 0) { do { node1 = node1.Nodes[node2.Nodes.Count - 1]; }while(node1.Nodes.Count != 0); } return(node1); } else { return(node1); } } else { // if we are not a first child of parent if (node1.Index > 0 && node1.Index < node1.Parent.Nodes.Count) { TreeNode node2 = node1.Parent.Nodes[node1.Index - 1]; node1 = node2; // find last child of new selected node if (node2.Nodes.Count > 0) { do { node1 = node1.Nodes[node2.Nodes.Count - 1]; }while(node1.Nodes.Count != 0); } return(node1); } else // first child of parent { return(node1.Parent); } } } return(null); }
public bool Remove(ITreeNode item) { TreeNode treeNode = nodes.Cast <TreeNode>().First(tn => tn.Tag == item); if (!nodes.Contains(treeNode)) { return(false); } nodes.Remove(treeNode); return(true); }
public void AddValueTest2() { var parent = new TreeNode <String>(); var target = new TreeNodeCollection <String>(parent); var expected = RandomValueEx.GetRandomString(); var actual = target.Add(expected); var actual1 = target.Add(expected); Assert.Equal(2, target.Count); Assert.True(target.Contains(actual)); Assert.True(target.Contains(actual1)); Assert.Same(parent, actual.Parent); Assert.Equal(actual.Value, expected); Assert.Equal(1, actual.Depth); Assert.Same(parent, actual1.Parent); Assert.Equal(actual1.Value, expected); Assert.Equal(1, actual1.Depth); }
public static TreeNode FindNextNode(TreeNodeCollection nodes, TreeNode selected) { if (nodes != null && nodes.Count > 0) { TreeNode node1 = (selected == null) ? nodes[0] : selected; TreeNode backup = node1; if (node1.Nodes.Count > 0) // if we have child the show it first { return(node1.Nodes[0]); } else { TreeNode node2 = node1; while (node2 != null) { if (node2.Parent == null || nodes.Contains(node2) == true) // if we on the top of tree { if (node2.Index < nodes.Count - 1) // check can we select next node or not { return(nodes[node2.Index + 1]); } else // we on the last node in tree { // if we on last child of tree node if (node2 != backup) { return(backup); } return(node2); } } else // if we have a parent node { node1 = node2.Parent; if (node2.Index < node1.Nodes.Count - 1) // can we select next node { return(node1.Nodes[node2.Index + 1]); } else // go to the parent { node2 = node1; } } } } } return(null); }
/// <summary> /// Add TreeNode /// </summary> /// <param name="nodes">node collection</param> /// <param name="treeNode">TreeNode</param> /// <param name="iImageIndex">image index</param> /// <param name="checkboxState">check box state</param> /// <returns></returns> protected TreeNode AddTreeNode(TreeNodeCollection nodes, TreeNode treeNode, CheckBoxState checkboxState) { if (!nodes.Contains(treeNode)) { nodes.Add(treeNode); } this.SetTreeNodeState(treeNode, checkboxState); SetTreeNodeAndChildrenStateRecursively(treeNode, checkboxState); SetParentTreeNodeStateRecursively(treeNode.Parent); return(treeNode); }
public void AddNodeTestCase1() { var parent = new TreeNode<String>(); var target = new TreeNodeCollection<String>( parent ); var item = new TreeNode<String>(); target.Add( item, false ); Assert.IsTrue( target.Contains( item ) ); Assert.AreEqual( 1, target.Count ); Assert.IsNull( item.Parent ); Assert.AreEqual( 0, item.Depth ); }
public void RemoveNodeTest1() { var parent = new TreeNode <String>(); var target = new TreeNodeCollection <String>(parent); var item = new TreeNode <String> { Parent = parent }; var result = target.Remove(item); Assert.False(result); Assert.Same(parent, item.Parent); Assert.False(target.Contains(item)); }
public void AddNodeTest1() { var parent = new TreeNode <String>(); var target = new TreeNodeCollection <String>(parent); var item = new TreeNode <String>(); target.Add(item, false); Assert.True(target.Contains(item)); Assert.Equal(1, target.Count); Assert.Null(item.Parent); Assert.Equal(0, item.Depth); }
private static bool IsChild(TreeNodeCollection nodes, TreeNode node, int maxLevel) { if (nodes.Contains(node)) { return(true); } foreach (TreeNode n in nodes) { if (n.Level < maxLevel && IsChild(n.Nodes, node, NODE_LEVEL_CLASS)) { return(true); } } return(false); }
public void AddValueTest1() { var parent = new TreeNode <String>(); var target = new TreeNodeCollection <String>(parent); String expected = null; // ReSharper disable once ExpressionIsAlwaysNull var actual = target.Add(expected); Assert.True(target.Contains(actual)); Assert.Equal(1, target.Count); // ReSharper disable once ExpressionIsAlwaysNull Assert.Equal(actual.Value, expected); Assert.Same(parent, actual.Parent); Assert.Equal(1, actual.Depth); }
/// <summary> /// This handles unselecting nodes as required if the Ctrl key is being pushed, as well /// as trcking the beginning of Shft-Click selections. /// </summary> /// <param name="p_tndSelectNode">The node that was selected.</param> /// <returns><c>true</c> if the node selection was handled; /// <c>false</c> otherwise.</returns> private bool HandleNodeSelection(TreeNode p_tndSelectNode) { if (MultiSelect) { if (((ModifierKeys & Keys.Control) > 0) && m_tncSelectedNodes.Contains(p_tndSelectNode)) { SelectedNodes.Remove(p_tndSelectNode); return(true); } if (ModifierKeys != Keys.Shift) { m_tndFirst = p_tndSelectNode; } } return(false); }
// <snippet2> // <snippet1> private void EnumerateTreeNodes() { TreeNodeCollection myNodeCollection = myTreeView.Nodes; // Check for a node in the collection. if (myNodeCollection.Contains(myTreeNode2)) { myLabel.Text += "Node2 is at index: " + myNodeCollection.IndexOf(myTreeNode2); } myLabel.Text += "\n\nElements of the TreeNodeCollection:\n"; // Create an enumerator for the collection. IEnumerator myEnumerator = myNodeCollection.GetEnumerator(); while (myEnumerator.MoveNext()) { myLabel.Text += ((TreeNode)myEnumerator.Current).Text + "\n"; } }
public override void Result(object result) { HandlerAsync.EnterArgs enterArgs = result as HandlerAsync.EnterArgs; if (enterArgs != null) { TreeNode node = new TreeNode(enterArgs.name); node.Tag = enterArgs.obj; stack.Push(node); Console.WriteLine("Enter: " + node.Text); } else { TreeNode node = stack.Pop(); Console.WriteLine("Exit: " + node.Text); //System.Diagnostics.Debug.Assert(node.Tag == state, node.Text); if (builder.Leaf(result)) { TreeNode n = node; // Add all nodes on the stack that hasn't already got a parent if (n.Parent == null) { foreach (TreeNode p in stack) { p.Nodes.Add(n); if (p.Parent != null) { n = null; break; } n = p; } if (n != null && !nodes.Contains(n)) { nodes.Add(n); } } } } }
public void qwerty(TreeNodeCollection tncoll, string strNode) { foreach (TreeNode tnode in tncoll) { if (tnode.Text.Contains(strNode)) { try { tnode.Expand(); } catch { } foreach (TreeNode treeNode in tnode.Nodes) { if (tncoll.Contains(tnode)) { } else { tnode.Nodes.Add(tnode.Text); } } } else { } qwerty(tnode.Nodes, strNode); } }
public bool Contains(TriStateTreeNode item) { return(_tnc.Contains(item)); }
/// <summary> /// Determines whether the collection contains a specific node. /// </summary> /// <param name="node">The node to locate in the collection.</param> /// <returns><c>true</c> if <paramref name="node"/> is found in the collection; otherwise, <c>false</c>. /// </returns> public bool Contains(Node node) { return(_base.Contains(node)); }
public void AddValueTestCase1() { var parent = new TreeNode<String>(); var target = new TreeNodeCollection<String>( parent ); String expected = null; var actual = target.Add( expected ); Assert.IsTrue( target.Contains( actual ) ); Assert.AreEqual( 1, target.Count ); Assert.AreEqual( actual.Value, expected ); Assert.AreSame( parent, actual.Parent ); Assert.AreEqual( 1, actual.Depth ); }
public bool Contains(TreeNode item) { return(_collection.Contains(item)); }
public void RemoveNodeTestCase2() { var parent = new TreeNode<String>(); var target = new TreeNodeCollection<String>( parent ); var item = new TreeNode<String>(); target.Add( item ); var item1 = new TreeNode<String>(); target.Add( item1 ); var result = target.Remove( item, false ); Assert.IsTrue( result ); Assert.AreSame( parent, item.Parent ); Assert.IsFalse( target.Contains( item ) ); result = target.Remove( item1, false ); Assert.IsTrue( result ); Assert.AreSame( parent, item1.Parent ); Assert.IsFalse( target.Contains( item1 ) ); Assert.AreEqual( 0, target.Count ); }
public void RemoveNodeTestCase1() { var parent = new TreeNode<String>(); var target = new TreeNodeCollection<String>( parent ); var item = new TreeNode<String> { Parent = parent }; var result = target.Remove( item ); Assert.IsFalse( result ); Assert.AreSame( parent, item.Parent ); Assert.IsFalse( target.Contains( item ) ); }
public void AddValueTestCase2() { var parent = new TreeNode<String>(); var target = new TreeNodeCollection<String>( parent ); var expected = RandomValueEx.GetRandomString(); var actual = target.Add( expected ); var actual1 = target.Add( expected ); Assert.AreEqual( 2, target.Count ); Assert.IsTrue( target.Contains( actual ) ); Assert.IsTrue( target.Contains( actual1 ) ); Assert.AreSame( parent, actual.Parent ); Assert.AreEqual( actual.Value, expected ); Assert.AreEqual( 1, actual.Depth ); Assert.AreSame( parent, actual1.Parent ); Assert.AreEqual( actual1.Value, expected ); Assert.AreEqual( 1, actual1.Depth ); }