DataGridViewCheckBoxColumn:如何在属性更新绑定的数据源,而不是改变了验证 [英] DataGridViewCheckBoxColumn: how to update bound DataSource on property changed instead of on validation
问题描述
我有绑定一个DataGridView的数据源的BindingList;所述TSource属性之一被绑定到一个DataGridViewCheckBoxColumn,但是当该复选框点击出现在数据源不被更新,但是当焦点上的复选框本身就会丢失。
我知道类似的事情发生在一个标准WindowsForms时DataSourceUpdateMode是OnValidation而不是OnPropertyChanged约束力,但我怎么能有一个DataGridViewCheckBoxColumn相同的结果?
列定义如下:
DataGridViewCheckBoxColumn列=新DataGridViewCheckBoxColumn();
column.DataPropertyName =myProperty的;
column.HeaderText =标题; dataGridView.Columns.Add(列);
您可以通过处理 DataGridView的
CurrentCellDirtyStateChanged
事件做到这一点code>。
无效dataGridView1_CurrentCellDirtyStateChanged(对象发件人,EventArgs的发送)
{
如果(dataGridView1.IsCurrentCellDirty)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
I've got a BindingList binded as the data source of a DataGridView; one of the TSource properties is binded to a DataGridViewCheckBoxColumn, but the data source is updated not when a click on the checkbox occurs, but when the focus on the checkbox itself is lost.
I know that something similar happens on a standard WindowsForms binding when the DataSourceUpdateMode is "OnValidation" instead of "OnPropertyChanged", but how can I have the same results with a DataGridViewCheckBoxColumn?
The column is defined as follows:
DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
column.DataPropertyName = "MyProperty";
column.HeaderText = "Title";
dataGridView.Columns.Add(column);
You can do this by handling the CurrentCellDirtyStateChanged
event of the DataGridView
.
void dataGridView1_CurrentCellDirtyStateChanged(object sender,EventArgs e)
{
if (dataGridView1.IsCurrentCellDirty)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
这篇关于DataGridViewCheckBoxColumn:如何在属性更新绑定的数据源,而不是改变了验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!