如何显示在模块中创建的ComboBox项目 [英] How to display ComboBox Items created in a Module

查看:108
本文介绍了如何显示在模块中创建的ComboBox项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将在模块中创建的组合框项目添加到表单中的组合框?我试图调用子例程,但它仍然无法正常工作.

How do I add ComboBox Items created in a Module to a ComboBox in a Form? I''ve tried to Call the Sub Routine but it still doesn''t work. What can I do to make it word?

推荐答案

从模块中,您必须通过实现IEnumerable接口的公共对象来公开项目.然后,在代码中,将该对象分配给组合框的datasource属性.

例如:

From the module you have to expose the items through a public object which implements the IEnumerable interface. Then, in code, assign the object to the datasource property of the combobox.

For example:

Module MyModule

  Public MyItemHolder as New Collection(Of String) = {"Item 1", "Item 2", "Item 3"}

End Module



然后,在表单中,也许在New事件期间,您需要将集合分配给组合框的datasource属性.



Then, in your form, maybe during the New event, you need to assign the collection to the combobox''s datasource property.

'Set the combobox datasource property to the collection
 TargetComboxBox.Datasource = MyModule.MyItemHolder



重要的是您不能绑定到模块或模块公开的方法...您必须绑定到通过该模块公开的对象,但是该对象必须实现IEnumerable.普通的集合和类型化的集合特别是实现了该接口.您还可以使用还实现INotifyPropertyChanged的Observable集合.这将允许您在运行时从组合框添加/删除对象.但是,这是一个更大的主题,您应该参考Google以获得更多信息. (几年前,《 MSDN杂志》上有一些有关Observable Collections的文章)

HTH,
杰森



The important thing is that you can''t bind to a module or the method exposed by a module... you have to bind to an object exposed through that module but the object must implement IEnumerable. Collections in general and Typed Collections, specifically, implement that interface. You can also use an Observable Collection which also implements INotifyPropertyChanged. This would allow you to add/remove objects from the combobox at runtime. However, that is a much bigger subject which you should refer to Google for more information on. (MSDN Magazine had some articles a few years ago on Observable Collections)

HTH,
Jason


这篇关于如何显示在模块中创建的ComboBox项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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