我有一个 Telerik Treeview 控件,我添加了关于 RemoveAt(0)
的问题当有 1 个元素无法删除该项目时。这怎么可能?
这是我的例子:
- ParentNode
|- child1
|- child2
TreeViewNode.Nodes
是 RadTreeNodeCollection
对象
RadTreeNodeCollection
是 NotifyCollection<RadTreeNode>
NotifyCollection<T>
是 Collection<T>
(有通知属性变化接口(interface))
和 Collection<T>
是基本的微软集合
所以这是一个示例来解释正在发生的事情:
// 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
失败?
* 编辑 *
我只是替换所有 RadTreeView
(telerik TreeView
)和RadTreeNode
(telerik TreeNode
) 标准 Microsoft TreeView
和 TreeNode
并且代码运行良好,所以它不是 Tag
有问题的属性。
最佳答案
通过将 RadTreeview
更改为 TreeView
并将所有对 RadTreeNode
的引用更改为 TreeNode
来解决此问题使用完全相同的代码一切正常。
关于c# - RemoveAt 收集失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42144724/