[英]Combo box data source binding doesn't show text when data is updated in data grid view
I have bound a data grid view and a combo box to my table (which is managed by Entity Framework): 我已经将数据网格视图和组合框绑定到了我的表(由Entity Framework管理):
eraDataGridView.DataSource = BillContext.Eras.Local.ToBindingList();
eraComboBox.DataSource = BillContext.Eras.Local.ToBindingList();
eraComboBox.DisplayMember = "Name";
and I have created a save button for the data grid view: 并且我为数据网格视图创建了一个保存按钮:
private void saveEras_Click(object sender, EventArgs e) {
BillContext.SaveChanges();
saveEras.Enabled = false;
}
When I insert a new row to the data grid view; 当我在数据网格视图中插入新行时; if I select another row after I finish editing the row (by clicking on another row, pressing tab or enter) and then click on the save button everything works as expected, but if I press the save button without changing the row;
如果我在完成编辑行后选择另一行(通过单击另一行,按Tab或Enter),然后单击保存按钮,则一切按预期进行,但是如果我按保存按钮而不更改该行; the combo box will have a new item without text(which is the new row but without the text).
组合框将有一个没有文本的新项目(这是新行,但没有文本)。
How can I make the combo box show the text of the newly added row in the described scenario? 在上述情况下,如何使组合框显示新添加的行的文本? Any workarounds would be appreciated.
任何解决方法将不胜感激。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.