c# - RemoveAt 收集失败

标签 c# winforms telerik .net-4.6

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

这是我的例子:

- ParentNode
   |- child1
   |- child2

TreeViewNode.NodesRadTreeNodeCollection对象
RadTreeNodeCollectionNotifyCollection<RadTreeNode>
NotifyCollection<T>Collection<T> (有通知属性变化接口(interface))
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有问题的属性。

最佳答案

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

关于c# - RemoveAt 收集失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42144724/

相关文章:

c# - 我可以通过函数传递参数属性吗?

c# - Winform 工具提示内存泄漏。来自 timer_tick 的自配置控制

c# - 如何在 Entity Framework 迁移中获取当前连接字符串?

c# - 很好的泛型介绍

c# - WinForms中常见的 "Drag and Drop"图标如何实现

c# - 默认控制台窗口的文本颜色

.net - Telerik Rad 文本框和 javascript 问题

c# - 未能从文本 'Path' 创建 '(RadButtonOnImage:RadButtonImage.Image)'

ios - nativescript 如何使元素对触摸事件透明

c# - 可以制作一个 C# 属性,该属性是 Entity Framework 代码首次迁移获取的其他属性的组合