Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to have Controls.AddRange to add collectionbase

1 view
Skip to first unread message

smartscottiedog

unread,
Dec 7, 2009, 3:04:21 PM12/7/09
to
Hi,
I have a class where it has Button in collection and it is declared
like this.

public class ButtonArray : System.Collections.CollectionBase

It has methods to add and delete buttons and handles clicks, etc.
Works fine as is in a form.

I would like to add this to Controls.AddRange of FlowLayoutPanel which
expects Array of Control. How do I convert ButtonArray to Control
Array? Do I add ICollection and implement CopyTo? Or is there a
simpler solution?

Syntax example is greatly appreciated. Thanks.

Armin Zingler

unread,
Dec 7, 2009, 3:31:52 PM12/7/09
to
smartscottiedog schrieb:


Sorry, only VB.Net, but you'll get the point:


Dim o As New ButtonArray

'...
Controls.AddRange(o.Cast(Of Control)().ToArray())

--
Armin

smartscottiedog

unread,
Dec 7, 2009, 3:51:58 PM12/7/09
to

That did it. Here is the c#.

Controls.AddRange(o.Cast<Control>().ToArray())

Thanks again.

0 new messages