title: Combobox databinding through code
body: <p>i have this form where i am binding data with the controls. This is my code</p>
  
  <pre><code>Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  
      Try
          conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;;Data Source=c:\users\desraj\desktop\mydb.accdb;")
          conn.Open()
          formload()
  
          adap = New OleDbDataAdapter("select * from mytable", conn)
          Dim ds As New DataSet
          adap.Fill(ds, "mytable")
          BindingSource1.DataSource = ds.Tables(0)
          BindingNavigator1.BindingSource = BindingSource1
  
  
          TextBox1.DataBindings.Add("Text", BindingSource1, "id")
          TextBox2.DataBindings.Add("Text", BindingSource1, "myname")
  
  
          ComboBox1.DataBindings.Add("Text", BindingSource1, "city_code")
          ComboBox2.DataBindings.Add("Text", BindingSource1, "state_code")
  
  
      Catch ex As Exception
          MsgBox(ex.Message.ToString)
      End Try
  
  End Sub
  
  Public Sub formload()
      Try
          cmd = New OleDbCommand("select * from mycity", conn)
          reader = cmd.ExecuteReader
          While reader.Read = True
              ComboBox1.Items.Add(reader.Item(1))
          End While
          reader.Close()
  
          cmd = New OleDbCommand("select * from mystate", conn)
          reader = cmd.ExecuteReader
          While reader.Read = True
              ComboBox2.Items.Add(reader.Item(1))
          End While
          reader.Close()
      Catch ex As Exception
          MsgBox(ex.Message)
      End Try
  End Sub
  </code></pre>
  
  <p><br>
  i have 3 tables<br>
  table 1: <code>MYTABLE</code> with 4 columns<br>
  <code>id,myname,city_code(fk),state_code(fk)</code><br>
  table 2: <code>MYCITY</code> with 2 columns<br>
  <code>city_code,city</code><br>
  table 3: <code>MYSTATE</code> with 2 columns<br>
  <code>state_code,state</code><br>
  <br>
  For example:<br>
  <code>mytable</code> has following values<br>
  <code>ID</code> <code>myname</code> <code>city_code</code> <code>state_code</code><br>
  1  alan  2  3<br>
  2  rock  3  1<br>
  3  brock 1  2<br>
  <code>mycity</code> has following values<br>
  <code>city_code</code> <code>city</code><br>
  <code>1</code>  <code>abc</code> <br>
  <code>2</code>  <code>xyz</code> <br>
  <code>3</code>  <code>pqr</code> <br>
  <code>mystate</code> has following values<br>
  <code>state_code</code> <code>state</code><br>
  <code>1</code>  <code>lmn</code> <br>
  <code>2</code>  <code>fgh</code> <br>
  <code>3</code>  <code>def</code> <br></p>
  
  <p>The problem is that instead of loading <code>combobox1</code> and <code>combobox2</code> with city and state, it loads <code>city_code</code> and <code>state_code</code>.
  How can I load <code>city</code> and <code>state</code> in <code>combobox1</code> and <code>combobox2</code>, as i am having their foreign keys in <code>mytable</code>?</p>