title: Getting 'Unable to cast object of type' error when trying to loop through Button controls on Form
body: <p>In a <code>Form</code>, I added a <code>TableLayoutPanel</code>, and within that I add 5 buttons.</p>
  
  <p>At runtime, I add 10 buttons to Form1 in a loop. Then I use <code>foreach</code> to do something with those 10 buttons.</p>
  
  <pre><code>foreach (Button C in this.Controls)
      // do something
  </code></pre>
  
  <p>When I the run the program, an error appears:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Windows.Forms.TableLayoutPanel' to type 'System.Windows.Forms.Button'</p>
  </blockquote>
  
  <p>I think this error happens because the <code>TableLayoutPanel</code> contains 5 buttons in it.</p>
  
  <p>Yeah I can delete this <code>TableLayoutPanel</code> and add 5 buttons directly in the <code>Form</code>, but the <code>TableLayoutPanel</code> helps a lot in my code.</p>
  
  <p>So is there any solution to traverse those 10 buttons and still keep the <code>TableLayoutPanel</code>?</p>
  
  <p>Furthermore, can I traverse "buttons in Form" and "buttons in TableLayoutPanel" separately ?</p>