Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Can't get "TreeNodeCollection.Contains" to validate node

Can't get "TreeNodeCollection.Contains" to validate node

Scheduled Pinned Locked Moved C#
data-structuresannouncement
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JstDaNuGuy
    wrote on last edited by
    #1

    Trying to combine dbRecords that overlap to display as one unit on treeView. so rather than looking like: + dept1 + dept2 + dept2 + dept2 + dept3 + dept3 + dept4 I want it to look like: + dept1 + dept2 + dept3 + dept4 Using TreeNodeCollection.Contains Method to acheive this goal, but its not working. It seems that becuase i'm recreating the TreeNode object [TreeNode myNode = new TreeNode()] on each new loop it doesn't have anyway to refrenece the data i've already written. This makes sense, but it seems odd that i can't refrence the pre-written data inside of the tree. I've tried refrenceing the actual TreeView, (tView.Nodes.Contains(myNode) I've tried the locally written TreeNode (DeptNode.Nodes.Contains(myNode) I've tried doing a foreach loop[foreach(TreeNode node in tView.Nodes)] and checking doing if(node.Tag == myNode.Tag) I've tried removing the recreation of the TreeNode so it refrences the same node object when doing the search (i only ended up with the expected result of only adding the newest node to the TreeView rather than several new nodes) and pretty much i'm at wits end on what would work... Here's the code:

    private void TelList()
    {
    statusBarPanel1.Text = "Please Wait While We Update the List";

    		PhoneTree.Nodes.Clear();
    		TreeNode ParentNode = new TreeNode("Phone List");
    		TreeNode Purge = new TreeNode("Purge");
    		PhoneTree.Nodes.Add(ParentNode);
    		PhoneTree.Nodes.Add(Purge);
    
    
    		while (TreeRead.Read())
    		{
    			TreeNode DeptNode = new TreeNode();
    			TreeNode TelNode = new TreeNode();
    			TreeNode ModNode = new TreeNode();
    			DeptNode.Text = TreeRead.GetString(7);
    			DeptNode.Tag = TreeRead.GetValue(4);
    			ModNode.Text = TreeRead.GetString(2);
    			ModNode.Tag = TreeRead.GetValue(4);
    			TelNode.Text = TreeRead.GetString(3);
    			TelNode.Tag = TreeRead.GetValue(2);
    			if (ParentNode.Nodes.Contains(DeptNode))
    				{				
    					if (ModNode.Tag == DeptNode.Tag)
    					{
    						if (DeptNode.Nodes.Contains(ModNode))
    						{
    							if (ModNode.Nodes.Contains(TelNode))
    							{continue;}
    							else
    							{
    								ModNode.Nodes.Add(TelNode);
    							}
    						}
    						else
    						{
    							DeptNode.Nodes.Add(ModNode);
    						}
    
    					}
    					if (TelNode.Tag.ToString() == ModNode.Text)
    					{
    						ModNode.Nodes.Add(TelNode);
    					}
    				
    
    				}
    				else
    				{
    					ParentNode.Nodes.Add(DeptNod
    
    J 1 Reply Last reply
    0
    • J JstDaNuGuy

      Trying to combine dbRecords that overlap to display as one unit on treeView. so rather than looking like: + dept1 + dept2 + dept2 + dept2 + dept3 + dept3 + dept4 I want it to look like: + dept1 + dept2 + dept3 + dept4 Using TreeNodeCollection.Contains Method to acheive this goal, but its not working. It seems that becuase i'm recreating the TreeNode object [TreeNode myNode = new TreeNode()] on each new loop it doesn't have anyway to refrenece the data i've already written. This makes sense, but it seems odd that i can't refrence the pre-written data inside of the tree. I've tried refrenceing the actual TreeView, (tView.Nodes.Contains(myNode) I've tried the locally written TreeNode (DeptNode.Nodes.Contains(myNode) I've tried doing a foreach loop[foreach(TreeNode node in tView.Nodes)] and checking doing if(node.Tag == myNode.Tag) I've tried removing the recreation of the TreeNode so it refrences the same node object when doing the search (i only ended up with the expected result of only adding the newest node to the TreeView rather than several new nodes) and pretty much i'm at wits end on what would work... Here's the code:

      private void TelList()
      {
      statusBarPanel1.Text = "Please Wait While We Update the List";

      		PhoneTree.Nodes.Clear();
      		TreeNode ParentNode = new TreeNode("Phone List");
      		TreeNode Purge = new TreeNode("Purge");
      		PhoneTree.Nodes.Add(ParentNode);
      		PhoneTree.Nodes.Add(Purge);
      
      
      		while (TreeRead.Read())
      		{
      			TreeNode DeptNode = new TreeNode();
      			TreeNode TelNode = new TreeNode();
      			TreeNode ModNode = new TreeNode();
      			DeptNode.Text = TreeRead.GetString(7);
      			DeptNode.Tag = TreeRead.GetValue(4);
      			ModNode.Text = TreeRead.GetString(2);
      			ModNode.Tag = TreeRead.GetValue(4);
      			TelNode.Text = TreeRead.GetString(3);
      			TelNode.Tag = TreeRead.GetValue(2);
      			if (ParentNode.Nodes.Contains(DeptNode))
      				{				
      					if (ModNode.Tag == DeptNode.Tag)
      					{
      						if (DeptNode.Nodes.Contains(ModNode))
      						{
      							if (ModNode.Nodes.Contains(TelNode))
      							{continue;}
      							else
      							{
      								ModNode.Nodes.Add(TelNode);
      							}
      						}
      						else
      						{
      							DeptNode.Nodes.Add(ModNode);
      						}
      
      					}
      					if (TelNode.Tag.ToString() == ModNode.Text)
      					{
      						ModNode.Nodes.Add(TelNode);
      					}
      				
      
      				}
      				else
      				{
      					ParentNode.Nodes.Add(DeptNod
      
      J Offline
      J Offline
      JstDaNuGuy
      wrote on last edited by
      #2

      Hoping to get some more visiblity on my problem thx http://www.codeproject.com/script/comments/forums.asp?msg=1362841&forumid=1649#xx1362841xx[^] :-D :laugh: ;p :^) :sigh:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups