![](/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.