简体   繁体   English

ComboBox和Datagridview VB.Net

[英]ComboBox and Datagridview VB.Net

I'm working with a combox and datagridview. 我正在使用combox和datagridview。 What I am trying to accomplish (this is homework) is show a combobox where the user can pick an employee ID. 我要完成的工作(这是家庭作业)是显示一个组合框,用户可以在其中选择员工ID。 When the user chooses that ID the datagrid view displays sales for that employee's ID. 当用户选择该ID时,datagrid视图将显示该员工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. 首先,将我的employeeID设置为一个组合框(从“数据源”窗格上的数据源),然后拖放到表单中。 I clicked and set it to use databound items and set it to the same datasource as my datagrid view. 我单击并将其设置为使用数据绑定项,并将其设置为与我的datagrid视图相同的数据源。 Then I chose EmployeeID for my display member. 然后,我为显示成员选择了EmployeeID。

The datagrid view will load just fine and brings up every order. datagrid视图将很好地加载并调出每个订单。 The employeeID combobox will load several ID's and there are duplicates because an ID can be associated with seperate orders. employeeID组合框将加载多个ID,并且存在重复项,因为ID可以与单独的订单关联。 If I pick an ID it isolates the order that ID is associated with. 如果我选择一个ID,它将隔离与ID关联的顺序。 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? 是否可以对组合框进行排序,这样我就可以只显示一次employeeID,然后单击后对订单进行排序?

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. 它仍然有错误,但我想总比没有好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM