0
votes

I'm working with a combox and datagridview. What I am trying to accomplish (this is homework) is show a combobox where the user can pick an employee ID. When the user chooses that ID the datagrid view displays sales for that employee's ID.

I am coming up with all kinds of issues so I would like to restart and walk through the process. My form is fairly simple. Here is what I have done so far, please bear with me.

First I set my employeeID to a combobox (from the datasource on the datasources pane) and dragged and dropped to my form. I clicked and set it to use databound items and set it to the same datasource as my datagrid view. Then I chose EmployeeID for my display member.

The datagrid view will load just fine and brings up every order. The employeeID combobox will load several ID's and there are duplicates because an ID can be associated with seperate orders. If I pick an ID it isolates the order that ID is associated with. This is where I am stuck.

I don't have much code to show because of the way this was programmed (drag and drop) but I can show you what came up:

Public Class EmployeeOrdersForm

Private Sub EmployeeOrdersForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'NORTHWNDDataSet.Employees' table. You can move, or remove it, as needed.
    Me.EmployeesTableAdapter.Fill(Me.NORTHWNDDataSet.Employees)
    'TODO: This line of code loads data into the 'NORTHWNDDataSet.Employees' table. You can move, or remove it, as needed.
    Me.EmployeesTableAdapter.Fill(Me.NORTHWNDDataSet.Employees)
    'TODO: This line of code loads data into the 'NORTHWNDDataSet.Employees' table. You can move, or remove it, as needed.
    Me.EmployeesTableAdapter.Fill(Me.NORTHWNDDataSet.Employees)
    'TODO: This line of code loads data into the 'NORTHWNDDataSet.Order_Details' table. You can move, or remove it, as needed. 
    Me.OrdersTableAdapter.Fill(Me.NORTHWNDDataSet.Orders)

End Sub


Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

End Sub


Private Sub EmployeeIDComboBoxToolStripLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

End Class

Can someone point me in the right direction? Is it possible to sort the combobox so that way I can have it only display the employeeID once and then when clicked sort through the orders?

Thank you,

J

1
What is the ultimate purpose of the employee cbo? Is it to act as a filter - when you select #6 from it, then just your orders are displayed? why do you fill the EmployeesTableAdapter 3 times? TYPICALLY, the Employee ID is not displayed because what a person's DB ID is, really need not concern them. Instead, get the ID and Name into the datasource and display the name. They pick name, but your code actually uses ID for whatever it does. - Ňɏssa Pøngjǣrdenlarp
@Plutonix The user can pick an employeeID from the combo box and then it will sort through and load the sales that employee has made. I didn't realize I filled it 3 times. This project has been a headache for me. I guess I can delete some rows huh. - Jeremy B
When you bind a combobox like that you are actually storing DataRowView objects in it, YOu can set the DisplayMember to show the name, and set the ValueMember to ID which your code would use. Also you arent limited to using tables and their columns. Since it sounds statis, you could load First and LastName Adn ID into a List(of myEmp), put THOSE in the cbo so that Emp.FirstName & " " & Emp.LastName displays, and still use Emp.ID to filter the orders list. your question is very broad, but that should give you something to get started. - Ňɏssa Pøngjǣrdenlarp

1 Answers

0
votes

THis isnt the official answer but I was able to find a walk through in the book. It still has errors but I guess it's better than nothing.