I am having a strange issue where I have a combo box (5 of them)on my windows VB.NET form. All of them I have collection of items in design mode where the user can select from the list. I also have the first item on the list to be "Choose from the list" now My problem is this: Some of them work some don't for the first selection. When I first click "ADD NEW" button and I fill all the other text boxes and select from the list of the combo boxes, the first value on my combo box list is defaulted to "Choose from the list" which is the first item on the list. (2 out of the 5 combo boxes default to the first Item on the list and the other 3 shows the correctly chosen item on the list) and when I save and click "ADD NEW" button again and fill the text boxes and choose an item from the list for all the combo boxes and hit save they all work (and display the selected item) and I can see the selected Item. So the first entry defaults to " Choose from List" which is my first item on the combo box list for 2 out of the 5 combo boxes and the rest changed to the user selected item.
HERE is a snapshot of my CODE: as you can see on my description of the problem I am new to VB.NET.
BTW, I am using strongly typed dataset. (basically drag and drop method)
'Add new employee to DB Private Sub AddNewBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNewBtn.Click 'Clear Previous data on form. i.e if the user entered text before clicking on ADD Button. For Each ctrl As Control In Me.Controls Try If TypeOf (ctrl) Is CheckBox Then DirectCast(ctrl, CheckBox).Checked = False If TypeOf (ctrl) Is TextBox Then DirectCast(ctrl, TextBox).Clear() 'clear combobox previous values If EmpTypeComboBox.Items.Count > 0 Then EmpTypeComboBox.SelectedIndex = 0 ' EmpTypeComboBox.Text = " " 'Else ' EmpTypeComboBox.SelectedItem = EmpTypeComboBox.SelectedValue End If If EmpJobTitleComboBox.Items.Count > 0 Then EmpJobTitleComboBox.SelectedIndex = 0 End If If EmpCityComboBox.Items.Count > 0 Then EmpCityComboBox.SelectedIndex = 0 ' EmpCityComboBox.Text = " " End If If EmpStateComboBox.Items.Count > 0 Then EmpStateComboBox.SelectedIndex = 0 End If If EmpEducationLevelComboBox.Items.Count > 0 Then EmpEducationLevelComboBox.SelectedIndex = 0 End If Catch Exception As Exception MsgBox(Exception.Message & "Please click ADD NEW button to add new Employee. If error occurs after you click on New Button, re-start the program and perform operation again if necessary close program and re-start your computer", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Human Error") End Try Next 'Add new Employee to database SaveBtn.Enabled = True Try Me.EmployeeTblBindingSource.AddNew() EmpTypeComboBox.Focus() Catch Exception As Exception MsgBox(Exception.Message & "Database connections lost. Please re-start your program ") End Try HelpLabel.Text = "All fields are required to be completed EXCEPT Social Security field and Manager information" & vbNewLine & "The Social Security Field can be used to enter employee driving license number if desired for identification." 'set employee hired date to todays date EmpDateOfHireDateTimePicker.Value = DateTime.Now End Sub Private Sub SaveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveBtn.Click 'Validations for text boxes --Check for (.) and (-) and null enteries If EmpTypeComboBox.SelectedIndex = 0 Then MsgBox("Please choose Employee type from dropdown list", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Human Error") EmpTypeComboBox.Focus() Exit Sub End If If EmpJobTitleComboBox.SelectedIndex = 0 Then MsgBox("Please choose the Job title of the Employee you want to register from the dropdown list. If Employee job title is not show in the dropdown list, choose Other.", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Human Error") EmpJobTitleComboBox.Focus() Exit Sub End If Try ''Save the Employee entered to database Me.Validate() Me.EmployeeTblBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.DugsiDBDataSet) MsgBox("Employee registration Recorded", MsgBoxStyle.OkOnly, "Update/Save Successfull") Me.DugsiDBDataSet.Dispose() Me.TableAdapterManager.Dispose() Me.Refresh() 'Me.Close() Catch Exception As Exception MessageBox.Show(Exception.Message & "You have either not entered the required fields of the Employee you want to register or the database connection has been lost. If you are sure you've entered all of the require fields of the Employee you want to register and you seeing this error, please close the program and re-start the program, If the problem still exist, reboot your computer and if you are still getting the error please contact your system admin.") End Try
Thank you very much for your help iin advance