2017-02-09 82 views
2

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

这里是我有什么的一个示例:

- ParentNode 
    |- child1 
    |- child2 

TreeViewNode.NodesRadTreeNodeCollection对象
RadTreeNodeCollectionNotifyCollection<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 TreeViewTreeNode和代码运行正常所以它不是Tag属性,它是有问题的。

+1

'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

+0

'RemoveItem()'对象不存在。我最好的是'删除(节点)'和'删除(字符串对象名称)'并且都不起作用。 – Franck

+0

@Franck你确定你正在使用RadTreeNodeCollection?因为根据[文档](http://docs.telerik.com/devtools/winforms/api/html/m_telerik_wincontrols_ui_radtreenodecollection_removeitem.htm)有一个。 –

回答

0

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