title: How can i loop over all comboBoxes controls i have and add the items of each comboBox to a List?
body: <p>I tried :</p>
  
  <pre><code>var comboBoxes = this.Controls
                    .OfType&lt;ComboBox&gt;()
                    .Where(x =&gt; x.Name.StartsWith("comboBox"));
  
  foreach (var cmbBox in comboBoxes)
  {
      CMBXWMICLASSES.AddRange(cmbBox.Items[
  }
  </code></pre>
  
  <p>But inside the loop the foreach how do I add the Items of each ComboBox ?</p>
  
  <p>This is a working code:</p>
  
  <p>In the top of form1 i did:</p>
  
  <pre><code>List&lt;string&gt; CMBXWMICLASSES = new List&lt;string&gt;();
  </code></pre>
  
  <p>Then i added a method that make recursively process all controls and their children:</p>
  
  <pre><code>public IEnumerable&lt;Control&gt; GetAll(Control control, Type type)
          {
              var controls = control.Controls.Cast&lt;Control&gt;();
  
              return controls.SelectMany(ctrl =&gt; GetAll(ctrl, type))
                                        .Concat(controls)
                                        .Where(c =&gt; c.GetType() == type);
          }
  </code></pre>
  
  <p>Then adding the items from each ComboBox in the constructor:</p>
  
  <pre><code>var c = GetAll(this, typeof(ComboBox));
              foreach (ComboBox cc in c)
              {
                  foreach (string ccc in cc.Items)
                  {
                      CMBXWMICLASSES.Add(ccc);
                  }
              }
  </code></pre>