【问题标题】:RemoveAt on collection fails收集时的 RemoveAt 失败
【发布时间】:2017-02-09 18:55:04
【问题描述】:

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

这是我所拥有的示例:

- ParentNode
   |- child1
   |- child2

TreeViewNode.NodesRadTreeNodeCollection 对象
RadTreeNodeCollectionNotifyCollection<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 TreeViewTreeNode 并且代码运行良好,所以不是Tag 属性有问题.

【问题讨论】:

  • NotifyCollectiondocumentation 表明它没有暴露自己的RemoveAt。但它公开了一个基于索引的RemoveItem 方法。如果您将调用Collection&lt;T&gt;.RemoveAt 替换为调用NotifyCollection&lt;T&gt;.RemoveItem,会发生什么情况?对 Telerik 没有冒犯,但也许只是没有始终如一地实施。
  • RemoveItem() 对象不存在。我最好的是 Remove(Node)Remove(String objectname) 两者都不起作用。
  • @Franck 你确定你使用的是 RadTreeNodeCollection 吗?因为根据documentation 有一个。
  • @OfirWinegarten 这是私人的
  • 你是对的,对不起

标签: c# winforms telerik .net-4.6


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 2021-07-19
    • 2014-01-22
    • 1970-01-01
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    相关资源
    最近更新 更多