title: VB.net Windows form (Working with Access Database) displaying a selected combobox item in a textbox
body: <p>Hello All this is somewhat urgent as this assignment is due Sunday 11/12 at midnight </p>
  
  <p>I have attached what I need help with it is selecting a combobox item then getting the data to display in the textboxes below</p>
  
  <p>I really don't know how to approach it I double clicked the combobox and this is what I started with to try to just get the ID to display. I haven't attempted anything else. I commented out what I tried because it didn't work.</p>
  
  <pre><code>Public Class AppointmentsForm
      Private aAppointments As New Appointments
  
      'Instance of customers
      Private aCustomers As New Customers
  
  
      Private Sub AppointmentsForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
          'Combobox must always have a DataSource, Display Member, and Value Member
          'Load the ComboBox with customer name
  
          cboCustomer.DataSource = aCustomers.Items
          cboCustomer.DisplayMember = "CustName"
          cboCustomer.ValueMember = "CustId"
          cboCustomer.SelectedIndex = -1   'no items selected
  
  
          ' load the datagridview
          ApptDataGridView.DataSource = aAppointments.Items
  
          'do not show TypeID
  
          ApptDataGridView.Columns(1).Visible = False
          '.Columns(1) TypeID has index of 1 as it is Column 2 in the data sources
  
      End Sub
  
      Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
          'make sure that a record is selected first
          If ApptDataGridView.SelectedRows.Count &gt; 0 Then
              Dim apptid As Integer
              apptid = ApptDataGridView.SelectedRows(0).Cells(0).Value
  
              'Delete selected record by calling the delte function
              aAppointments.Delete(apptid)
          End If
      End Sub
  
      Private Sub btnEdit_Click(sender As System.Object, e As System.EventArgs) Handles btnEdit.Click
          'make sure row is selected get that row from the table ..... need to find by ID
          'This is a query which you will create in the class
          'Transfer information from that row to the form, display the form
          If ApptDataGridView.SelectedRows.Count &gt; 0 Then
              modAppointmentsForm.ApptID = ApptDataGridView.SelectedRows(0).Cells(0).Value
              modAppointmentsForm.ShowDialog()
          End If
      End Sub
  End Class
  </code></pre>
  
  <p>HERE IS THE CLASS FOR APPOINTMENTS:</p>
  
  <p>Public Class Appointments</p>
  
  <pre><code>Public adapter As New CompanyDataSetTableAdapters.SalesStaffTableAdapter
  
  'error variable
  Public Shared Property LastError As String
  
  Public ReadOnly Property Items() As DataTable
      Get
          Dim table As DataTable = adapter.GetData
          'sorted by Appointment id
          table.DefaultView.Sort = "ID"
          Return table
      End Get
  End Property
  
  'create a function to combine date and time
  Public Shared Function CombinedDateTime(aDate As DateTime, aTime As DateTime) As DateTime
      'declare timespan variable
      Dim tsDate As New TimeSpan(aTime.Hour, aTime.Minute, 0)
      Return aDate.Add(tsDate)
  
  End Function
  </code></pre>
  
  <p>HERE IS THE CLASS FOR CUSTOMERS:</p>
  
  <p>Public Class Customers</p>
  
  <pre><code>'create a object variable (tableadapter)
  'this will be used to creat instances of this class in the form
  
  Private adapter As New CompanyDataSetTableAdapters.SalesStaffTableAdapter
  
  'property to return a table using the GetData method
  Public ReadOnly Property Items() As DataTable
      Get
          Dim table As DataTable = adapter.GetData
          table.DefaultView.Sort = "First_Name"
          Return table
      End Get
  End Property
  
  'create a function to filter the customers by custid
  Public Function GetByCustomerId(custid As Short) As DataTable
      Dim table As DataTable = adapter.GetData 'entire table
      'filter to get desired row(s)
      table.DefaultView.RowFilter = " ID = " &amp; custid
      Return table
  
  End Function
  </code></pre>
  
  <p>End Class</p>
  
  <p>HERE IS THE CODE FOR THE FORM WITH THE COMBOBOX AND THE TEXTBOX'S SUCH AS ID, LASTNAME, FIRSTNAME, ETC. THAT NEED TO HAVE THE DATA DISPLAYED WHEN THE COMBOBOX ITEM IS SELECTED. AGAIN THE ID IS DISPLAYING WHEN I WRITE: IDTextBox.Text = SalesStaffComboBox.SelectedValue.ToString 
  BUT IF I DO THE SAME FOR THE OTHER TEXT BOXES (LastName.Text = SalesStaffComboBox.SelectedValue.ToString   <strong><em>_</em>____</strong> FirstName.Text = SalesStaffComboBox.SelectedValue.ToString )  THE ID NUMBER IS DISPLAYED IN THEM AS WELL. </p>
  
  <p>Public Class frmUpdateSalary
      'instances of the required classes
      Private aCustomers As New Customers
      Private aAppointments As New Appointments</p>
  
  <pre><code>Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
      Me.Close()
  End Sub
  
  
  Private Sub frmUpdateSalary_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  
      SalesStaffComboBox.DataSource = aCustomers.Items
      SalesStaffComboBox.DisplayMember = "First_Name"
       SalesStaffComboBox.ValueMember = "ID"
  
  
  End Sub
  
  Private Sub SalesStaffComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalesStaffComboBox.SelectedIndexChanged
      'fill the textboxes
      'Populate ID textbox with selected customer
  
  
      IDTextBox.Text = SalesStaffComboBox.SelectedValue.ToString
  
  
  
      End Sub
  </code></pre>