Sohrab Phoenix
Sohrab Phoenix

Reputation: 13

How to put all buttons in flowlayoutpanel to array?

I have a code in vb.net to select all buttons in form within flowlayoutpanel, but it returns zero.

I think problem is with flowlayoutpanel.

Dim alphabetButtons() As Button
alphabetButtons = Me.Controls.OfType(Of Button).Except(New Button() {Button1}).ToArray

Can you tell me what am I doing wrong?

Upvotes: 0

Views: 284

Answers (1)

Idle_Mind
Idle_Mind

Reputation: 39122

I have a code in vb.net to select all buttons in form within flowlayoutpanel, but it returns zero. ... Can you tell me what am I doing wrong?

Yes. You're telling the Form to return all Controls of Type Button:

Dim alphabetButtons() As Button
alphabetButtons = Me.Controls.OfType(Of Button).Except(New Button() {Button1}).ToArray

You need to ask the FlowLayoutPanel this question.

Change Me to the name of your FlowLayoutPanel, such as FlowLayoutPanel1 in the "fixed" code below:

Dim alphabetButtons() As Button
alphabetButtons = FlowLayoutPanel1.Controls.OfType(Of Button).Except(New Button() {Button1}).ToArray

The Controls() collection only returns controls that are directly contained by that container. Each container has its own collection of child controls...

Upvotes: 1

Related Questions