重命名SortedList的键 [英] Renaming the key of a SortedList

查看:77
本文介绍了重命名SortedList的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在列表框中显示了SortedList的所有键.当我右键单击所选键并选择重命名时,我希望能够在我的SortedList中重命名该特定键.

I have all the the keys of my SortedList displayed in a listbox. When i right-click on the selected key and select rename i want to be able to rename that specific key in my SortedList. How do i do that?

推荐答案

您不能在排序列表中更改项目的键.您必须删除现有项目,然后使用正确的密钥添加一个新项目.

好吧,在某些情况下可以间接更改它,但是由于不再对列表进行排序,因此它将破坏列表,并且操作假定列表如果进行了一些排序,您将得到未定义的结果.

或者,您可以使用列表而不是排序列表.

重命名项目时,是要它保留在当前位置还是要更新列表框项目的顺序?
You cannot change the key of an item in a sorted list. You have to remove existing item and add a new one with the proper key.

Well it would be possible to change it indirectly in some case but it would then broke the list since it would not be sorted anymore and operation assumes that the list if sorted some you would get undefined result.

Alternatively, you can use a list instead of a sorted list.

When you rename you item, do you want it to stay at the current location or you want to update listbox items order?


这篇关于重命名SortedList的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆