J
Joel Lyons
I have TreeNode-derived objects (MyTreeNode) that I store in a TreeView.
Before I add new nodes, I want to make sure a node with the same identity
(Text property) isn't already there. So, I overrode Object.Equals in a
MyTreeNode class like so:
public class MyTreeNode : TreeNode
{
...
public override bool Equals(object obj)
{
return true; //TODO: compare Text property instead
}
}
Obviously, that's not all it should do, but the problem is this method never
even gets called!
I add the new node like so:
MyTreeNode node = new MyTreeNode("testing");
if(!tvMyTreeView.Nodes.Contains(node))
tvMyTreeView.Nodes.Add(node);
What am I doing wrong?!
Before I add new nodes, I want to make sure a node with the same identity
(Text property) isn't already there. So, I overrode Object.Equals in a
MyTreeNode class like so:
public class MyTreeNode : TreeNode
{
...
public override bool Equals(object obj)
{
return true; //TODO: compare Text property instead
}
}
Obviously, that's not all it should do, but the problem is this method never
even gets called!
I add the new node like so:
MyTreeNode node = new MyTreeNode("testing");
if(!tvMyTreeView.Nodes.Contains(node))
tvMyTreeView.Nodes.Add(node);
What am I doing wrong?!