You can write your code on ComboBox
OnSelectedIndexChanged
Event to fill your TextBox with appropriate value. You can write your own reusable function for this. See the below code :
Public Sub FillTextBox(ByVal SelectField As String, ByVal TableName As String, ByVal ColumnName As String, ByVal ComboBoxName As ComboBox, ByVal SetTextBoxName As TextBox)
Dim _ObjDataAdapter As SqlDataAdapter = New SqlDataAdapter
_ObjDataAdapter.SelectCommand = New SqlCommand
_ObjDataAdapter.SelectCommand.Connection = _Connection
_ObjDataAdapter.SelectCommand.CommandText = "Select " & SelectField & " FROM " & TableName & " WHERE " & ColumnName & "='" & ComboBoxName.Text & "'"
Try
_ObjDataReader = _ObjDataAdapter.SelectCommand.ExecuteReader()
Catch ex As System.InvalidOperationException
MessageBox.Show(ex.ToString)
End Try
While _ObjDataReader.Read
SetTextBoxName.Text = _ObjDataReader.Item(0)
End While
_ObjDataReader.Close()
_ObjDataAdapter.SelectCommand = Nothing
End Sub
After that you can call this Function on ComboBox
OnSelectedIndexChanged
Event
FillTextBox("DisplayColumn", "TableName", "WhereClauseColumn", ComboBox1, TextBox1)
I hope this will help you. :)