We help IT Professionals succeed at work.
Get Started

Need listbox to display items from list collection

652 Views
Last Modified: 2013-11-26
To be totally upfront with everyone I needed to solve this problem for a class project. The time has passed to submit the project and I have submitted the project without it working correctly. Im seeking an answer to this question so that I can sleep at night!
I am self-taught, should be obvious from my example, and have made many simple databound applications in the past. I have worked with database and text files in the past without much problems.
This project uses a List to manage the following fields: Employee Name, Address, SSN and Title. On save it should add the info entered into the appropriate text boxes (EmployeeName_textbox, EmployeeAddress_textbox, EmployeeSSN_textbox, EmployeeTitle_textbox) to the List Employee. A list box should then be populated with the EmployeeName data for each entry. On selected item in the listbox all fields for that employee should populate the textbox and allow edit.
Again I am asking for my own piece of mind and your responses cant affect the grade since Ive already submitted my project.
Below is some of the code that was in my project. I could not get the listbox to populate with the EmployeeName and since it was never populated I never added the selected item code to display the info in the textboxes.
Thanks in advance!
Public Class mainForm
    Private EmployeeList As List(Of Employee)
    Private EmpCurrentIndex As Integer
Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        EmployeeList = New List(Of Employee)
        Call SetState("Start")
    End Sub
 Private Sub Save_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save_button.Click
Dim EmpCurrent As New Employee
If EmployeeName_textbox.Text = "" Then
MsgBox("Enter information to save employee or select 'Cancel'")
ElseIf EmployeeType_combo.Text = "" Then
MsgBox("You must select 'Type' to save employee")
ElseIf EmployeeName_textbox.Text <> "" Then
EmpCurrent.EmployeeName = EmployeeName_textbox.Text
EmpCurrent.EmployeeAddress = EmployeeAddress_textbox.Text
EmpCurrent.EmployeeSSN = EmployeeSSN_textbox.Text
EmpCurrent.EmployeeType = EmployeeType_combo.SelectedItem.ToString
EmployeeList.Add(EmpCurrent)
MsgBox("Employee " & EmployeeName_textbox.Text & " Saved.")
End If
Call SetState("Start")
End Sub
Private Sub Add_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add_button.Click
Call SetState("Add")
End Sub
Private Sub Cancel_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_button.Click
Call SetState("Clear")
End
Private Sub SetState(ByVal argState As String)
Select Case argState
Case "Clear"
                EmployeeName_textbox.Enabled = False
                EmployeeAddress_textbox.Enabled = False
                EmployeeSSN_textbox.Enabled = False
                EmployeeType_combo.Enabled = False
                EmployeeName_textbox.Text = ""
                EmployeeAddress_textbox.Text = ""
                EmployeeSSN_textbox.Text = ""
                EmployeeType_combo.SelectedItem = ""
                Exit_button.Enabled = True
                Add_button.Enabled = True
                Cancel_button.Enabled = False
                Save_button.Enabled = False
                Change_button.Enabled = False
                Delete_button.Enabled = False
            Case "Start"
                EmployeeName_textbox.Text = ""
                EmployeeAddress_textbox.Text = ""
                EmployeeSSN_textbox.Text = ""
                EmployeeType_combo.Text = ""
                Exit_button.Enabled = True
                Add_button.Enabled = True
                Cancel_button.Enabled = False
                Save_button.Enabled = False
                Change_button.Enabled = False
                Delete_button.Enabled = False
            Case "Add"
                EmployeeName_textbox.Enabled = True
                EmployeeAddress_textbox.Enabled = True
                EmployeeSSN_textbox.Enabled = True
                EmployeeType_combo.Enabled = True
                EmployeeName_textbox.Text = ""
                EmployeeAddress_textbox.Text = ""
                EmployeeSSN_textbox.Text = ""
                EmployeeType_combo.SelectedItem = ""
                EmployeeName_textbox.Focus()
                Exit_button.Enabled = False
                Add_button.Enabled = False
                Cancel_button.Enabled = True
                Save_button.Enabled = True
                Change_button.Enabled = False
                Delete_button.Enabled = False
            Case "Editing"
                Exit_button.Enabled = False
                Add_button.Enabled = False
                Cancel_button.Enabled = True
                Save_button.Enabled = True
                Change_button.Enabled = False
                Delete_button.Enabled = True
        End Select
    End Sub
End Class

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE