VB.NET - Make list box selection show other details in textboxes

Asked By kibika on 03-Jan-13 12:04 PM
I am populating a list box from Ms Access database with several fields from a specific table(EmployeeInfo). What I want to do is on selection of an item int he list box, display each field in the table to respective textboxes.
sundar k replied to kibika on 04-Jan-13 05:42 PM
try the below code
For i As Integer = 0 To <listboxvariablename>.SelectedItems.Count - 1
    <textboxcontrolname>.Text &= DirectCast(
.SelectedItems(i), DataRowView)(1).ToString & vbCrLf Next

Make list box selection show other details in textboxes - kibika replied to sundar k on 05-Jan-13 12:34 AM

I am using the code below. I have a list box in which there are some some names of people, on selecting a name, the details pertaining on the selected name should be displayed in textboxes. I am using the following code but it does not work. What am I doing wrong or how do I use your code to make it run.


Private Sub lstEmployees_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstEmployees.SelectedIndexChanged
  Dim dbSource As String = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Payroll.mdb"
  Dim db_command As New OleDbCommand, reader As OleDbDataReader
  con.ConnectionString = dbSource
  db_command.CommandText = "Select * from Employees where EmployeeNo = " & lstEmployees.SelectedIndex.ToString & ""
  db_command.Connection = con
  reader = db_command.ExecuteReader()
  If (reader.read()) Then
  TextBox1.Text = reader("FirstName").ToString
  TextBox2.Text = reader("LastName").ToString
  End If
  End Sub