我有一个Telerik Treeview控件,并且当有1个元素无法删除项目时,我添加了RemoveAt(0)
的问题。这怎么可能呢?删除收集失败
这里是我有什么的一个示例:
- ParentNode
|- child1
|- child2
TreeViewNode.Nodes
是RadTreeNodeCollection
对象
RadTreeNodeCollection
是NotifyCollection<RadTreeNode>
NotifyCollection<T>
是Collection<T>
(具有通知属性改变的接口)
和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
属性,它是有问题的。
'NotifyCollection'的[documentation](http://docs.telerik.com/devtools/winforms/api/html/t_telerik_collections_generic_notifycollection_1.htm)显示它不公开它自己的'RemoveAt'。但它暴露了一个基于索引的'RemoveItem'方法。如果您通过致电'NotifyCollection .RemoveItem'替换了对'Collection .RemoveAt'的调用,会发生什么情况? Telerik没有冒犯,但也许只是没有一贯地执行。 –
dlatikay
'RemoveItem()'对象不存在。我最好的是'删除(节点)'和'删除(字符串对象名称)'并且都不起作用。 – Franck
@Franck你确定你正在使用RadTreeNodeCollection?因为根据[文档](http://docs.telerik.com/devtools/winforms/api/html/m_telerik_wincontrols_ui_radtreenodecollection_removeitem.htm)有一个。 –