以OO方式填充下拉列表 [英] populate a drop down in a OO manner

查看:94
本文介绍了以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 a Product 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''s DataSource property to ProductList, then you set it''s DisplayMember property to Description, and it''s ValueMember 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''s SelectedItem property.

Hope this helps


这篇关于以OO方式填充下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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