开发者

Dynamically create more than one instance of class and reference it

I want to dynamically create more than one instance of the BindingSource class to be public throughout my Form.

If I use Dim o As Object = Activator.CreateInstance(GetType(BindingSource)) it will only create one instance of this class.

How can I create multiple instances of this class and reference them uniquely.

The number of instances needed is not known at design time, so I cannot do开发者_Go百科

Dim o1 As Object = Activator.CreateInstance(GetType(BindingSource))
Dim o2 As Object = Activator.CreateInstance(GetType(BindingSource))
Dim o3 As Object = Activator.CreateInstance(GetType(BindingSource))

It's in vb.net

I hope I make sense...

Regards Marius


Your design doesn't make any sense. But, I'll answer your question, and you can ask a new question to puzzle out the flaws in your design.

Make a dynamic collection, such as List<BindingSource> that you can add to as needed.

Then, in a loop, you can instantiate as many BindingSource as you need, and add them to the List<BindingSource> as needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜