DataGridViewCheckBoxColumn: how to update the associated DataSource with a property changed instead of checking

I have a BindingList connected as a DataGridView data source; one of the TSource properties is tied to a DataGridViewCheckBoxColumn, but the data source is updated not when a click on a flag appears, but when the focus on the flag itself is lost.

I know something like this happens with standard WindowsForms binding, when the DataSourceUpdateMode is "OnValidation" instead of "OnPropertyChanged", but how can I get 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); 
+6
source share
1 answer

You can do this by handling the CurrentCellDirtyStateChanged DataGridView event.

 void dataGridView1_CurrentCellDirtyStateChanged(object sender,EventArgs e) { if (dataGridView1.IsCurrentCellDirty) { dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit); } } 
+9
source

Source: https://habr.com/ru/post/891292/


All Articles