title: C# combo box value and display using invoke method
body: <p>I am using <a href="http://en.wikipedia.org/wiki/Windows_Forms" rel="nofollow noreferrer">Windows Forms</a>, and I have a combo box with the values:</p>
  <blockquote>
  <p>Apple <br/>
  Oranges <br/>
  Pairs <br/></p>
  </blockquote>
  <p>My text box contains values 1, 2 and 3,</p>
  <p>apple = 1 and oranges = 2 and pairs = 3.</p>
  <p>This relation is in my table on SQL, fields Account and Name. How do I change the value of the textbox to = 2 if the combo box is selected as oranges?</p>
  <p>Basically this is reference to a program I'm working on that has an account combo box that displays the accounts names (user friendly). I need the names ID account number to then be displayed in the text box. From this text box I can then pass the value into my stored procedure that will get all the information on that account.</p>
  <h2>Update</h2>
  <p>The above text is out of date. See below!</p>
  <p>A note to add is that my code gets the account details and populates my combo box.</p>
  <p>Is there an easy way to do this? Or does this require joining in C# similar to SQL joins on tables?</p>
  <p>Or without using a text box at all, basically my combo would have 2 fields orange, 2 but only display oranges to the user, but my other method uses the second field 2.</p>
  <p>OK, so this part adds the acc field to the combo box.</p>
  <pre><code>{
      SqlCommand accountFill = new SqlCommand(&quot;SELECT name, acc FROM dbo.Customer&quot;, conn1);
      SqlDataReader readacc = accountFill.ExecuteReader();
  
      while (readacc.Read())
      {
          AddItem(readacc.GetString(0).ToString(), readacc, &quot;name&quot;, &quot;acc&quot;);
      }
      conn1.Close();
  }
  </code></pre>
  <p>Add item is an invoke method used by my task.</p>
  <pre><code>private void AddItem(string value, Object dataSource, string name, string acc)
  {
      if (accCollection.InvokeRequired)
      {
          accCollection.Invoke(new Action&lt;string,Object,string,string&gt;(AddItem), new Object[] { value });
      }
      else
      {
          //accCollection.Items.Add(value);
          accCollection.DataSource = dataSource;
          accCollection.DisplayMember = name;
          accCollection.ValueMember = acc;
      }
  }
  </code></pre>
  <p>ERROR complex databinding accepts as a datasource iether an i.list or an i.list source at datasource.</p>