对ListBox中的重复项进行编号 [英] Numbering Duplicate Items in the ListBox
问题描述
我有一个列表框。在其他地方,我有一个按钮,可以将listboxitems添加到列表框中(当程序处于活动状态时)。每个listboxitem添加给我相同的名称。在WPF,C#或.vb示例代码中,如何自动在重复项的末尾添加一个数字,使其与下一个不同(如果在Windows中创建新文件夹,则第一个文件夹不具有一个数字,但下一个文件夹将有2和更高的数字取决于你创建的新文件夹的数量)?
编辑:我不知道为什么有人会这样做不可理解。一定是真的,人们不能在互联网上阅读多个句子:P
总而言之,我需要知道(IN CODE)如何在动态创建的listboxitems中的实际文本旁边的文本框中显示数字:
ex:< br $>
[新类别]
[新类别2]
[新类别3]
[新类别4]
[新类别5]
[新类别6]
[+]
I have a listbox. Elsewhere, I have a button that adds listboxitems to the listbox (when the program is active). Each listboxitem addition gives me the same name. In WPF, C#, or .vb sample code, how do I add a number to the end of the duplicate item automatically that will make it different from the next (Like in Windows if you create new folders, the first folder won't have a number but the next folders will have numbers 2 and up depending on how many new folders you create)?
I don't know why someone would make this as not understandable. It must be true that people can't read more than one sentence on the internet :P
To sum it up, I need to know (IN CODE) how to make numbers appear in the textbox beside the actual text in dynamically created listboxitems:
ex:
[New Category ]
[New Category 2]
[New Category 3]
[New Category 4]
[New Category 5]
[New Category 6]
[ + ]
推荐答案
这里解释了我过去收集的一些答案: combobox.selectedvalue在winform中显示{} [ ^ ]。
这个想法是:你不应该在列表中存储字符串vie w或组合框,您应该创建一些表示每个项目及其数据的类或结构。通过覆盖System.Object.ToString()
来解决在屏幕上呈现此类项目的问题。我提到的一些过去的答案都附有详细的代码示例,请查看它们。
-SA
This is explained in few of my past answers collected here: combobox.selectedvalue shows {} in winform[^].
The idea is: you should not store strings in a list view or a combo box, you should create some class or structure representing each item with its data. The problem of presentation of such items on screen is solved by overridingSystem.Object.ToString()
. Some of my referenced past answers are complete with detailed code samples, please see them.
—SA
这篇关于对ListBox中的重复项进行编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!