2017-02-09 97 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的問題解決了問題,並且它使用完全相同的代碼正常工作。