RemoveAt 收集失败

RemoveAt on collection fails

我有一个 Telerik Treeview 控件,当有 1 个元素无法删除该项目时,我添加了 RemoveAt(0) 问题。这怎么可能?

这是我的例子:

- ParentNode
   |- child1
   |- child2

TreeViewNode.Nodes 是一个 RadTreeNodeCollection 对象
RadTreeNodeCollection 是一个 NotifyCollection<RadTreeNode>
NotifyCollection<T> 是一个 Collection<T> (with notify 属性 change interfaces)
Collection<T> 是基本的 Microsoft 集合

所以这是一个示例来解释正在发生的事情:

// get parent node called "ParentNode" result is not null
var parentNode = treeview1.Nodes[0];

// get quantity of nodes result is 2
var qtyNodes = parentNode.Nodes.Count;

// try removing the first node : this calls Collection<T>.RemoveAt(T);
parentNode.Nodes.RemoveAt(0);

// here count is still 2

// removing the tag from the node which contain model informations
parentNode.Nodes[0].Tag = null;

// try removing the first node again
parentNode.Nodes.RemoveAt(0);

// now the count is 1 so the item really got removed

标签与Collection.RemoveAt()有什么关系? 我还有另一种情况,从节点中删除标签也不起作用。那么对象的哪些其他属性会导致 Collection.RemoveAt 失败?

* 编辑 * 我只是用标准的 Microsoft TreeViewTreeNode 替换所有 RadTreeView (telerik TreeView) 和 RadTreeNode (telerik TreeNode) 并且代码运行很好,所以不是 Tag 属性 有问题。

通过将 RadTreeview 更改为 TreeView 并将所有对 RadTreeNode 的引用更改为 TreeNode 来解决此问题,并且使用完全相同的代码都可以正常工作。