添加新行时 dataGridview 列中的默认值出现问题
我有一个带有 dataGridView 的表单 (form1),其中列出了名为“Orders”的表中的客户订单。当在 dataGridView 中选择订单并按下 Enter 键时,会弹出另一个表单 (form2)。此弹出 form2 有另一个 dataGridView,支持添加行,用户在其中将与所选订单相关的新记录输入到名为“OrderDetails”的表中,该表具有名为 OrderNumber 的外键列,该列引用 OrderNumber 列在表“订单”中。
问题:
当用户从 form2 上的 dataGridView 输入新记录到 orderDetails 表中时,我希望自动填充 OrderNumber 列。它的值应该是 form1 上所选记录的订单号值,这样用户就不必手动键入它,因为它是已知的。帮助。
datagridview 绑定到 bidningSource。
I have a form (form1) with a dataGridView listing customer orders from a table called "Orders". When an order is selected in the dataGridView and the EnterKey is pressed, another form (form2) pops-up. This popup form2 has another dataGridView that supports adding rows where the user enters a new record related to the selected order into a table called "OrderDetails" which has a foreigh key column called OrderNumber which refers to the OrderNumber column in table "Orders".
Problem:
when the user is entering a new record from the dataGridView on form2 into the orderDetails table, i want the OrderNumber column to be populated automatically. Its value should be the order number value of the selected record on form1 such that the user doesn't have to type it manually since its already known. Help.
The datagridview is bound to a bidningSource.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
刚刚让它按照我想要的方式工作
just got it working the way i wanted with
您可以捕获 BindingSource 上的一个名为“AddingNew”的事件。您可以在此处指定新对象及其属性。像这样:
There's an event on a BindingSource you can catch called 'AddingNew'. Here you can specify what the new object and its properties will be. Like this: