Can't get "TreeNodeCollection.Contains" to validate node
-
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 doingif(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
-
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 doingif(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
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: