我有一个DataGridView绑定到列表。值显示很好,当我点击一个值时,它开始编辑,但是当我按下Enter时,这个改变被忽略了,没有数据被改变。当我在Value setter中放置一个断点时,我可以看到它在编辑之后执行,但没有显示更改过的数据。我的绑定代码如下所示:可编辑的DataGridView绑定到列表
namespace DataGridViewList
{
public partial class Form1 : Form
{
public struct LocationEdit
{
public string Key { get; set; }
private string _value;
public string Value { get { return _value; } set { _value = value; } }
};
public Form1()
{
InitializeComponent();
BindingList<LocationEdit> list = new BindingList<LocationEdit>();
list.Add(new LocationEdit { Key = "0", Value = "Home" });
list.Add(new LocationEdit { Key = "1", Value = "Work" });
dataGridView1.DataSource = list;
}
}
}
该项目是一个基本的Windows窗体项目,在设计人员创建一个DataGrid的列称为键和值分别设置DataPropertyName以键/值。没有值被设置为只读。
有没有我失踪的一些步骤?我需要实施INotifyPropertyChanged
还是其他?
你能展示一些更多的代码吗?例如,像编辑/确认事件处理程序? –
@PiotrJustyna我没有这样的处理程序。我必须添加一个吗? – Suma
发生什么事情是您的数据网格对基础列表中的更改一无所知。每次更改该值时,请使用ResetBindings方法(http://msdn.microsoft.com/zh-cn/library/system.windows.forms.control.resetbindings.aspx)通知网格。 –