0

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?

dimoniy
  • 5,820
  • 2
  • 24
  • 22
  • you'll probably have add a few examples of things you tried in order to receive any help. You can always update your question. Welcome to stack overflow, recommended reading: http://stackoverflow.com/help/how-to-ask – Dan Beaulieu Jun 29 '15 at 18:12

1 Answers1

1

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...

Idle_Mind
  • 38,363
  • 3
  • 29
  • 40