数据绑定设置:
bindingSource1.DataSource = dataset.Tables[0];
dataGridView1.DataSource = bindingSource1;
checkBox1.DataBindings.Add("Checked", bindingSource1, "Sign", true, DataSourceUpdateMode.OnPropertyChanged);
textBox7.DataBindings.Add("Text", bindingSource1, "Street", true, DataSourceUpdateMode.OnPropertyChanged);
现象描述:
在正常情况下,因为设置了DataSourceUpdateMode.OnPropertyChanged ,当改变 checkbox 、textbox 的值 或者 修改 datatset.Tables[0] 中的datarow[index] 值 时,datagridview 中对应的单元格的值会立即发生变化。但是实际datagridview 中的值并未改变
解决办法:
经分析,发现 dataGridView1.DataSource 中表的值已发生改变,只是未显示在界面上,所以让他显示(重绘)就ok了。在某行的值发生改变时,使用 this.dataGridView1.InvalidateRow(RowIndex) 重绘界面即可。