将项添加到具有标记的列表框中 [英] Adding item to listbox that has tag

查看:93
本文介绍了将项添加到具有标记的列表框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些人可以帮帮我吗?



我想在运行期间将项目添加到列表框中(我知道如何做到这一点)。但我想为我添加的每个项目添加标签(数字标签)。这是可能的(不使用数据绑定)?因此,当用户单击列表框中的项目时,我可以读取数字标记。我知道我可以阅读用户选择的项目字符串,但我认为标签会更好。



i我正在使用vb.net windows应用程序

Can some please help me?

I want to add items to a listbox during runtime (i know how to do this). But i want to add tag(numerical tag) to each items that i add. Is that possible (without using data binding)? So when the user click the item in the listbox i can read the numberical tag. I know i can read string of item user selected but i think tag would be better.

i am using vb.net windows application

推荐答案

而不是'在每个项目上添加标签'你也可以用包含标签的对象填充列表框(因为列表框项是对象)。

例如,假设你的原始列表框包含字符串,那么你可以创建一个 Class ,比如说 MyData ,有两个属性:字符串和标签。然后,您可以使用 MyData Class 的实例(对象)填充列表框。因此,每个项目都包含原始字符串和数字标记。
Instead of 'adding a tag on each item' you might fill the listbox with objects containig the tag too (since listbox items are objects).
For instance, suppose your original listbox contains strings, then you could create a Class, say MyData, having two properties: the string and the tag. Then you might fill the listbox with instances (objects) of MyData Class. Hence every item would contain both the original string and the numeric tag.


这篇关于将项添加到具有标记的列表框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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