Inheritance: System.Windows.Forms.TreeNode
Exemple #1
0
        public void GetNodesOfTypeWithState()
        {
            m_treeView.Nodes.Clear();

            DummyTreeNode1 dNode  = new DummyTreeNode1("d");
            DummyTreeNode2 c2Node = new DummyTreeNode2("c2");
            DummyTreeNode2 c1Node = new DummyTreeNode2("c1", new TreeNode[] { dNode });

            m_bNode = new TreeNode("b", new TreeNode[] { c1Node, c2Node });
            m_aNode = new TreeNode("a", new TreeNode[] { m_bNode });
            m_treeView.Nodes.Add(m_aNode);

            m_treeView.SetChecked(c1Node, TriStateTreeView.CheckState.Checked);

            // Get Checked nodes of type DummyTreeNode1.
            TreeNode[] list = m_treeView.GetNodesOfTypeWithState(typeof(DummyTreeNode1),
                                                                 TriStateTreeView.CheckState.Checked);

            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(list[0], dNode);
            Assert.IsNotNull(list[0] as DummyTreeNode1);

            // Get Unchecked nodes of type DummyTreeNode2.
            list = m_treeView.GetNodesOfTypeWithState(typeof(DummyTreeNode2),
                                                      TriStateTreeView.CheckState.Unchecked);

            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(list[0], c2Node);
            Assert.IsNotNull(list[0] as DummyTreeNode2);

            // Get nodes of type DummyTreeNode2 regardless of check state (Unchecked, Checked or Greyed).
            list = m_treeView.GetNodesOfTypeWithState(typeof(DummyTreeNode2),
                                                      TriStateTreeView.CheckState.Unchecked |
                                                      TriStateTreeView.CheckState.Checked);

            Assert.AreEqual(2, list.Length);
            Assert.AreEqual(list[0], c1Node);
            Assert.AreEqual(list[1], c2Node);
            Assert.IsNotNull(list[0] as DummyTreeNode2);
            Assert.IsNotNull(list[1] as DummyTreeNode2);

            // Get nodes of type TreeNode regardless of check state (Unchecked, Checked or Greyed).
            list = m_treeView.GetNodesOfTypeWithState(typeof(TreeNode),
                                                      TriStateTreeView.CheckState.GreyChecked);

            Assert.AreEqual(2, list.Length);
            Assert.AreEqual(list[0], m_aNode);
            Assert.AreEqual(list[1], m_bNode);
            Assert.IsNotNull(list[0] as TreeNode);
            Assert.IsNotNull(list[1] as TreeNode);
        }
		public void GetNodesOfTypeWithState()
		{
			m_treeView.Nodes.Clear();

			DummyTreeNode1 dNode = new DummyTreeNode1("d");
			DummyTreeNode2 c2Node = new DummyTreeNode2("c2");
			DummyTreeNode2 c1Node = new DummyTreeNode2("c1", new TreeNode[] { dNode });
			m_bNode = new TreeNode("b", new TreeNode[] { c1Node, c2Node });
			m_aNode = new TreeNode("a", new TreeNode[] { m_bNode });
			m_treeView.Nodes.Add(m_aNode);

			m_treeView.SetChecked(c1Node, TriStateTreeView.CheckState.Checked);

			// Get Checked nodes of type DummyTreeNode1.
			TreeNode[] list = m_treeView.GetNodesOfTypeWithState(typeof(DummyTreeNode1),
				TriStateTreeView.CheckState.Checked);

			Assert.AreEqual(1, list.Length);
			Assert.AreEqual(list[0], dNode);
			Assert.IsNotNull(list[0] as DummyTreeNode1);

			// Get Unchecked nodes of type DummyTreeNode2.
			list = m_treeView.GetNodesOfTypeWithState(typeof(DummyTreeNode2),
				TriStateTreeView.CheckState.Unchecked);

			Assert.AreEqual(1, list.Length);
			Assert.AreEqual(list[0], c2Node);
			Assert.IsNotNull(list[0] as DummyTreeNode2);

			// Get nodes of type DummyTreeNode2 regardless of check state (Unchecked, Checked or Greyed).
			list = m_treeView.GetNodesOfTypeWithState(typeof(DummyTreeNode2),
				TriStateTreeView.CheckState.Unchecked |
				TriStateTreeView.CheckState.Checked);

			Assert.AreEqual(2, list.Length);
			Assert.AreEqual(list[0], c1Node);
			Assert.AreEqual(list[1], c2Node);
			Assert.IsNotNull(list[0] as DummyTreeNode2);
			Assert.IsNotNull(list[1] as DummyTreeNode2);

			// Get nodes of type TreeNode regardless of check state (Unchecked, Checked or Greyed).
			list = m_treeView.GetNodesOfTypeWithState(typeof(TreeNode),
				TriStateTreeView.CheckState.GreyChecked);

			Assert.AreEqual(2, list.Length);
			Assert.AreEqual(list[0], m_aNode);
			Assert.AreEqual(list[1], m_bNode);
			Assert.IsNotNull(list[0] as TreeNode);
			Assert.IsNotNull(list[1] as TreeNode);
		}