簡體   English   中英

實體框架如何將文本框綁定到Windows窗體中的模型

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM