I am filling a combobox using the values from a data table of employee names - see below.
All of the records in the table contain names there are no blank records.
Public Sub FillEmployeeOnlyCbo(ByRef MyCombo As ComboBox)
Dim MyQuery As String
' AutocomleteMode = SuggestAppend
' AutocompleSource= ListItems
' DropdownStyle = dropdown
MyQuery = "SELECT DISTINCT RTRIM(name) AS name FROM employee ORDER BY name"
Dim da As SqlDataAdapter = New SqlDataAdapter(MyQuery, SQLConnection)
Dim dt As DataTable = New DataTable
da.Fill(dt)
MyCombo.DataSource = dt
MyCombo.DisplayMember = "name"
MyCombo.ValueMember = "name"
MyCombo.Text = ""
End Sub
The AutocompleteMode is SuggestAppend, AutocompleteSource is ListItems and DropdownStyle is dropdown.
This is so that as I start to type the name, the name is displayed.
This combobox is on a tab page and then I load the form and click on the page, instead of the combobox being blank it has the first employee name in the list.
I couldn't understand why, so I copied the combobox to the first tab and when the form is loaded the combo box is blank.
If I enter a name in the combobox, close the form and load it again then the combobox contains the first entry in the list.
I'm not sure what I am doing wrong.
All of the records in the table contain names there are no blank records.
Public Sub FillEmployeeOnlyCbo(ByRef MyCombo As ComboBox)
Dim MyQuery As String
' AutocomleteMode = SuggestAppend
' AutocompleSource= ListItems
' DropdownStyle = dropdown
MyQuery = "SELECT DISTINCT RTRIM(name) AS name FROM employee ORDER BY name"
Dim da As SqlDataAdapter = New SqlDataAdapter(MyQuery, SQLConnection)
Dim dt As DataTable = New DataTable
da.Fill(dt)
MyCombo.DataSource = dt
MyCombo.DisplayMember = "name"
MyCombo.ValueMember = "name"
MyCombo.Text = ""
End Sub
The AutocompleteMode is SuggestAppend, AutocompleteSource is ListItems and DropdownStyle is dropdown.
This is so that as I start to type the name, the name is displayed.
This combobox is on a tab page and then I load the form and click on the page, instead of the combobox being blank it has the first employee name in the list.
I couldn't understand why, so I copied the combobox to the first tab and when the form is loaded the combo box is blank.
If I enter a name in the combobox, close the form and load it again then the combobox contains the first entry in the list.
I'm not sure what I am doing wrong.