title: Why does ComboBox.SelectedIndexChanged event fire three times before form load?
body: <p>I have a little problem with combobox databinding. I have a form that has one combobox and based on the selection in the ComboBox the form should be filled with data. I use the SelectedIndexChanged event instead of SelectionChangeCommitted because I want to be able to fill the form with the data of the first item in the  ComboBox when the form loads. I have tried 2 solutions:  </p>
  
  <ol>
  <li>Add the event handler before Data Binding.  </li>
  </ol>
  
  <p>This solution almost works as it should. It selects the first ComboBox item and fills the form with relevant data but for some reason this event fires three times when binding data and this makes the form loading slow because some data gets called from a database and basically this data is being loaded 3 times.</p>
  
  <ol start="2">
  <li>Add the event handler after Data Binding.  </li>
  </ol>
  
  <p>This solution doesn't work like I'd want to because it doesn't fill the form with the relevant data although the first item is correctly selected in the ComboBox after form load. This is mainly because I add the event handler (fills the form with data) after the Data Binding is done. The good thing about this solution is that the event is not being fired 3 times in a row, but that's the only good thing about this solution because the form is not being filled with relevant data like intended.  </p>
  
  <p>Does anyone have any idea why this event is getting fired 3 times? As a possible way to fix the problem I could call the method, that should be fired by the event, after Data Binding and then add event handler to the ComboBox, but this looks like a hackish way of doing things. If someone can provide a better way to get things done I'd be really happy. However, if my solution happens to be the only/best way of doing things, then can someone maybe tell me technical reasons for the event firing multiple times during Data Binding?  </p>
  
  <p>EDIT: I guess I found the reason and solution already. The reason the event got fired 3 times wasn't that data binding fired it 3 times - it was because assigning DisplayMember and ValueMember fired this event too.</p>
  
  <p>Before:  </p>
  
  <pre><code>combo.SelectedIndexChanged += new System.EventHandler(this.combo_SelectedIndexChanged);
  combo.DataSource = getItems().ToList();  
  combo.ValueMember = "Key";  
  combo.DisplayMember = "Value";  
  </code></pre>
  
  <p>After:  </p>
  
  <pre><code>combo.ValueMember = "Key";
  combo.DisplayMember = "Value";  
  combo.SelectedIndexChanged += new System.EventHandler(this.combo_SelectedIndexChanged);
  combo.DataSource = getItems().ToList();
  </code></pre>