![](/img/trans.png)
[英]How To Encrypt ConnectionString for Entity Framework and Windows Forms
[英]Entity Framework How to bind textbox to model in Windows Forms
在Windows Forms Project中使用Entity数据模型,我想同时将Orders实体绑定到datagridview和textBox,并且textBox必须根据datagrid中的当前行显示OrderID值。
接下来是我在表单加载事件中使用的代码:
using(NorthwindEntities context = new NorthwindEntities())
{
ordersDataGridView.DataSource = context.Orders;
OrderNumberTextBox. ...
}
对于这种情况,绑定文本框的正确语法是什么? 谢谢。
将BindingSource
对象绑定到context.Orders
,将DataGridView
绑定到BindingSource
,然后通过TextBox.DataBindings
属性,将TextBox
适当属性绑定到BindingSource
。 BindingSource对象将管理货币状态,以便当您在DataGridView中选择其他项目时,TextBox会更改。
绑定看起来类似于以下内容:
OrderNumberTextBox.DataBindings("Text", bindingSource, "OrderID");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.