以OO方式填充下拉列表 [英] populate a drop down in a OO manner
本文介绍了以OO方式填充下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
您只需要有一个要用于选择的类,将其称为Product
类.让此Product类具有4个属性,ProductID,Description,Price和StockLevel.首先要做的是将其中的一组收集到List< Product>中.称为此产品列表.然后在表单中插入一个ComboBox,将其DataSource
属性设置为ProductList,然后将其DisplayMember
属性设置为Description,并将其ValueMember
属性设置为ProductID.这将用列表填充ComboBox,并允许用户选择单个产品,可以通过Combo的SelectedItem
属性进行访问.
希望对您有帮助
i want to populate a dropdown in object oriented manner. how can i do soo?
解决方案
You just need to have a class that you want to use for selection, call it aProduct
class. Let this Product class have 4 Properties, ProductID, Description, Price and StockLevel. The first thing to do is gather a group of these into a List<Product> call this ProductList. Then in your form you insert a ComboBox, set it''sDataSource
property to ProductList, then you set it''sDisplayMember
property to Description, and it''sValueMember
property to ProductID. This will populate the ComboBox with the List, and allow the user to select an individual product, which will be accessible through the Combo''sSelectedItem
property.
Hope this helps
这篇关于以OO方式填充下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文