title: ComboBox.Item.AddRange(string[]) VS. ComboBox.DataSource = string[]
body: <p>So, I have two options:</p>
  
  <pre><code>aComboBox.Item.AddRange(stringArray);
  aComboBox.SelectedItem = stringFromStringArray;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>aComboBox.DataSource = stringArray;
  aComboBox.SelectedItem = stringFromStringArray;
  </code></pre>
  
  <p>Now, the first one is waaaaay slower when it comes to initialization (about 5-6 times). It does set the selected item properly, but still, it's very slow so I decided to go with the second one.</p>
  
  <p>But, if I use the second one, the Items array within the <code>aComboBox</code> is not yet set when the second command is executed, so the selected item is the one at index 1, instead the one specified.</p>
  
  <p>The question is, how do I get the performance of the second one with the functionality of the first one?</p>
  
  <p>EDIT:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace ComboBoxTest
  {
  class MainWindow : Form
  {
      string[] list = new string[1548];
      TableLayoutPanel panel = new TableLayoutPanel();
  
      public MainWindow() : base()
      {
          Height = 2000;
          Width = 1000;
  
          Random rand = new Random();
  
          for (int i = 0; i &lt; 1547; i++)
          {
              list[i] = rand.Next().ToString();
          }
  
          list[1547] = 5.ToString();
  
          Button button = new Button();
          button.Text = "Press me";
          button.Click += Button_Click;
  
          panel.Controls.Add(button, 0, 0);
  
          panel.Height = 2000;
          panel.Width = 1000;
  
          Controls.Add(panel);
  
          Show();
      }
  
      private void Button_Click(object sender, EventArgs e)
      {
          for (int i = 0; i &lt; 36; i++)
          {
              ComboBox box = new ComboBox();
              box.DataSource = list;  //box.Items.AddRange(list);
              box.SelectedItem = 5.ToString();
  
              panel.Controls.Add(box, 0, i+1);
          }
      }
  }
  }
  </code></pre>
  
  <p>I reproduced the problem with this program. If you change it to <code>addRange()</code>, it will take a lot more time, but it will set the item.</p>
  
  <p>Try adding a breakpoint to the <code>SelectedItem</code> and then look at the <code>ComboBox</code>.
  If you set the one, the other will be null (<code>DataSource</code> vs. <code>Items</code>). The <code>ComboBox</code> seems to look into <code>Items</code> to check if the string exists within the list, and that's why it fails with <code>DataSource</code> method.</p>
  
  <p>Bonus question: Why are all <code>ComboBoxes</code> working as one (try changing the value)?</p>