如何在两个单独的列表框中关联对象? [英] How to relate objects in two separate list boxes?

查看:114
本文介绍了如何在两个单独的列表框中关联对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Basic帮助



所以我需要创建两个列表框。第一个列表框告诉你项目(比如衬衫a,b和c)...第二个列表框应该是每个可用衬衫的数量(假设20个可用于衬衫a,b,c各个)



我需要弄清楚如何关联两个列表框,这样当你输入数据时(例如A的5件衬衫被卖掉)你会看到衬衫的数量A从20到15.



这有意义吗?我不是在寻找具体的代码,只是关于如何关联两个列表框的指导。

我应该寻找什么?

解决方案

解决这个问题的主要步骤不是列表框中的字符串字符串,而是自己存储对象;比你可以轻松比较对象。所有列表框类型(顺便说一句,你使用哪一个?确保在提出这些问题时指定类的确切全名)支持。唯一的问题是:在UI中的列表框项目文本中会显示什么呢?答案非常简单:无论 ToString()返回,所以你应该更好地覆盖 System.Object.ToString()在列表框项目的类型中。



有关详细信息,请参阅我过去的答案:

combobox.selectedvalue在winform中显示{} [ ^ ],

包含小数的排序列表 [ ^ ]。



-SA

Visual Basic Help

So I need to create two list boxes. The first listbox tells you the items(lets say shirts a,b, and c)...the second listbox is supposed to be the number of shirts available for each (lets say 20 available for shirt a,b,c each)

I need to figure out how to relate both listboxes so that when you enter data (such as 5 shirts of A were sold) You will see that the number of shirts for A goes from 20 to 15.

Does this make sense? I'm not looking for specific code, just guidance on how to relate two listboxes.
What should I be looking for?

解决方案

The major step to this problem is not string string on the list boxes, but storing the object themselves; than you can easily compare the objects. All the list box types (which one do you use, by the way? make sure you specify exact full name of the class when you ask such questions) support that. The only problem is: what will be shown in a list box item text in UI then? The answer is very simple: whatever ToString() returns, so you should better override System.Object.ToString() in the types of the list box items.

For more detail, please see my past answers:
combobox.selectedvalue shows {} in winform[^],
Sorted listbox with fractional numbers[^].

—SA


这篇关于如何在两个单独的列表框中关联对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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