【发布时间】:2017-02-09 18:55:04
【问题描述】:
我有一个 Telerik Treeview 控件,当有 1 个元素无法删除该项目时,我添加了 RemoveAt(0) 的问题。这怎么可能?
这是我所拥有的示例:
- ParentNode
|- child1
|- child2
TreeViewNode.Nodes 是 RadTreeNodeCollection 对象RadTreeNodeCollection 是 NotifyCollection<RadTreeNode>NotifyCollection<T> 是 Collection<T>(带有通知属性更改接口)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 失败呢?
* 编辑 *
我只需将所有RadTreeView (telerik TreeView) 和RadTreeNode (telerik TreeNode) 替换为标准Microsoft TreeView 和TreeNode 并且代码运行良好,所以不是Tag 属性有问题.
【问题讨论】:
-
NotifyCollection的documentation 表明它没有暴露自己的RemoveAt。但它公开了一个基于索引的RemoveItem方法。如果您将调用Collection<T>.RemoveAt替换为调用NotifyCollection<T>.RemoveItem,会发生什么情况?对 Telerik 没有冒犯,但也许只是没有始终如一地实施。 -
RemoveItem()对象不存在。我最好的是Remove(Node)和Remove(String objectname)两者都不起作用。 -
@Franck 你确定你使用的是 RadTreeNodeCollection 吗?因为根据documentation 有一个。
-
@OfirWinegarten 这是私人的
-
你是对的,对不起
标签: c# winforms telerik .net-4.6