DataGridView update datasource directly after changed Checkbox value
Posted
by
SchlaWiener
on Stack Overflow
See other posts from Stack Overflow
or by SchlaWiener
Published on 2011-01-03T15:49:52Z
Indexed on
2011/01/03
15:54 UTC
Read the original article
Hit count: 229
I have a System.Windows.Forms DataGridView that is bound to a List<MyObject>
.
The class MyObject contains a boolean property that is bound to DataGridViewCheckboxCell within the DataGridView.
public class MyObject
{
public decimal DefaultValue {get; set; }
public bool HasCustomValue {get;set; }
public decimal CustomValue {get;set; }
public decimal CurrentValue
{
get
{
return HasCustomValue
? CustomValue
: DefaultValue;
}
}
If I change the value of HasCustomValue
another (readonly) property CurrentValue
changes it's value, too.
That is done by implementing the INotifyPropertyChanged event (I left that part in the source example for simplicity)
If I changed HasCustomValue
from outside the DataGridView, the column bound to CurrentValue
gets updated immediately.
Howevery, If the users enables/disables the checkbox, HasCustomValue
is not changed in the underlying datasource unless he leaves the column by clicking with the mouse or pressing the TAB key.
Is there a way to force the grid to update the datasource directly after changing a checkbox value?
If I bind a Control Property I have the ability to set the DataSourceUpdateMode
to Windows.Forms.DataSourceUpdateMode.OnPropertyChanged
but I haven't found anything like that in a DataGridView
© Stack Overflow or respective owner