ComboBox and Datagridview VB.Net - vb.net

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

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.

Related

DataGridViewer how to get value of cell in newly selected row

Good day,
I am trying to create a media player in vb.net. I have a sql local database setup with meta data of certain users songs. They have been displayed in the DataGridViewer in my form to dislay to the user the songs they can play. Im now wanting to implement a procedure that can return the value of "SONG_NAME" in the users selected row when the grid is clicked.
DataGrid Viewer Contents
The settings of my DataGridViewer have multiselect off and the selection mode to Full row select. I have done some research but have found little outlining how to fetch the value of a certain column in the selection. Any help would be greatly appreciated as i am fairly new to Vb.net.
maybe this code can help
Private Sub DataGridView1_CellClick(ByVal sender As System.Object,
ByVal e As DataGridViewCellEventArgs) _
Handles DataGridView1.CellClick
MessageBox.Show(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString)
End Sub

Sorting of Data grid view which is bound table

I want my first column sort of data grid view when form load. but i have no code. Below i attach my loding code.
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'EmployeeTBDataSet.Table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.EmployeeTBDataSet.Table1)
End Sub
You have presumably dragged a table from the Data Sources window onto your form to create that DataGridView and the code that populates the DataTable it is bound to. That will also have created a BindingSource and that is where you perform most actions related to the bound data, including sorting. After that call to Fill, set the Sort property of that BindingSource to the name of the column you want to sort by, e.g.
Me.Table1BindingSource.Sort = "Table1ID"
That will sort in ascending order implicitly. You can also sort in ascending or descending order explicitly, e.g.
Me.Table1BindingSource.Sort = "Table1ID DESC"

Select and Show new Tab on control when values in txtbox change, but keep focus on txtbox

I'm having this issue that should be pretty easy to solve but I just can't seem to figure it out or find an answer yet. I have the following code:
Public Sub NotifyThatValuesChanged(sender As Object, e As EventArgs)
APIUserForm_MAIN.OnSecurityInputValuesChanged()
APIUserForm_MAIN.MessageSender.TabControl.SelectTab(0)
End Sub
So, I'm rasing events when values within txtboxes change, and one of the things I want to do is change tab focus when these values change, which it is doing...but....I don't want the cursor (or focus) to change to the selected tab. I want the cursor/focus to stay where it is at while this event happens, and for the tab selected on this other control to change from (1) to (0).
Thanks for the help!!!!
I don't think it's 100% possible. Try putting the focus back into the textbox:
Public Sub NotifyThatValuesChanged(sender As Object, e As EventArgs)
APIUserForm_MAIN.OnSecurityInputValuesChanged()
APIUserForm_MAIN.MessageSender.TabControl.SelectTab(0)
TextBox1.Select()
End Sub
If multiple controls are calling this method, you can use the sender parameter:
DirectCast(sender, Control).Select()

how to clear a listview from another form in vb.net

I would like to know, how to clear a list view items from an another form. For instance, I have Form A with a ListView, I would like to clear the Form A ListView Items from Form B. What I tried is, create a function in Form A to clear the listView and call that function from Form B. But it is not working. Please help me to resolve this issue.
Here is a quick and easy way to do so; this removes all items from listbox using a for each...
Private Sub btnClearListView_Click(sender As System.Object, e As System.EventArgs) Handles btnClearListView.Click
For Each I In FormA.ListView1.Items
FormA.ListView1.Items.Remove(I)
Next
End Sub
Thanks!

Datagridview not saving changes to DB when Navigator save changes clicked

This is a VB.NET, Winforms App, Using EF. On my form I have a datagridview, a databinding source, and a bindingNavigator... I can edit the cells of the datagridview but when I click save changes the value is only saved until I reload the form.?.? Looking at the database table directly I can see the value never actually changes.. Below is the sub that handles the click..
Private Sub UnitBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UnitBindingNavigatorSaveItem.Click
UnitDataGridView.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange)
db.SaveChanges()
End Sub
From what I have read this seems like all I need to have but obviously its wrong somehow..
I made a work around for it for the time being... I simply use the CellEndEdit event and get the row info from that. Next I get the value of the column that holds the id and update the database from there. Seems like a long way around but is the only way I can get it to write any data at the moment...