title: Listbox selected item to textbox in Vb.net
body: <p>Sometimes simple code will make us big confusion. I researched this questions in internet from past few hours.</p>
  
  <p>I have a listbox, data will load from Access table. When i selected an item in listbox, i wanted to show that item in a textbox.</p>
  
  <p>i have tried some code as below, nothing worked for me:</p>
  
  <pre><code>Private Sub listBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listBox1.SelectedIndexChanged
      For i As Integer = 0 To listBox1.SelectedItems.Count - 1
          textBox1.Text &amp;= DirectCast(listBox1.SelectedItems(i), DataRowView)(1).ToString &amp; vbCrLf
      Next
  End Sub
  
  Private Sub listBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listBox1.SelectedIndexChanged
      textBox1.Text = listBox1.SelectedItem.Value
  End Sub
  </code></pre>
  
  <p>Here is the code that will give values to listbox from access table</p>
  
  <pre><code>Dim dataAdapter As New OleDbDataAdapter("select * from eval", connection)
  Dim ds As DataSet = New DataSet
  dataAdapter.Fill(ds, "eval")
  listBox1.DataSource = ds
  listBox1.DisplayMember = "eval"
  listBox1.ValueMember = "eval.eval"
  </code></pre>