NotifyPropertyChanged and ReadValue() not working
-
I'm using VS 2008 From a form I pass a class (
Facility
) to another class (FCalc
) in the instantiatorFacility
is a partial class and has the properties withNotifyPropertyChanged
in the setter The property in question is bound to a textbox text property. When theFacility
value is updated in theFCalc
class the textbox is not updated. TheNotifyPropertyChanged
event is fired but when I get back to the form the values between theFacility
object and the textbox are different. To try and force this through I have used the ReadValue on the DataBinding but this does not help.txtROE.DataBindings[0].ReadValue();
I have tested the values of the textbox and the object directly after ReadValue() and they are different. Any suggestions are welcome
Never underestimate the power of human stupidity RAH
-
I'm using VS 2008 From a form I pass a class (
Facility
) to another class (FCalc
) in the instantiatorFacility
is a partial class and has the properties withNotifyPropertyChanged
in the setter The property in question is bound to a textbox text property. When theFacility
value is updated in theFCalc
class the textbox is not updated. TheNotifyPropertyChanged
event is fired but when I get back to the form the values between theFacility
object and the textbox are different. To try and force this through I have used the ReadValue on the DataBinding but this does not help.txtROE.DataBindings[0].ReadValue();
I have tested the values of the textbox and the object directly after ReadValue() and they are different. Any suggestions are welcome
Never underestimate the power of human stupidity RAH
Nothing springs to mind but I found Bind Better with INotifyPropertyChanged[^], don't know if it helps/applies in your situation.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.
-
I'm using VS 2008 From a form I pass a class (
Facility
) to another class (FCalc
) in the instantiatorFacility
is a partial class and has the properties withNotifyPropertyChanged
in the setter The property in question is bound to a textbox text property. When theFacility
value is updated in theFCalc
class the textbox is not updated. TheNotifyPropertyChanged
event is fired but when I get back to the form the values between theFacility
object and the textbox are different. To try and force this through I have used the ReadValue on the DataBinding but this does not help.txtROE.DataBindings[0].ReadValue();
I have tested the values of the textbox and the object directly after ReadValue() and they are different. Any suggestions are welcome
Never underestimate the power of human stupidity RAH
I managed to get the desired result by dropping and rebuilding the binding
//rebuild the databinding for the textbox
txtROE.DataBindings.Clear();
Binding oBinding = new Binding("Text", oFSet, "ROE");
oBinding.FormatString = "#,#.00";
oBinding.FormattingEnabled = true;Never underestimate the power of human stupidity RAH
-
I'm using VS 2008 From a form I pass a class (
Facility
) to another class (FCalc
) in the instantiatorFacility
is a partial class and has the properties withNotifyPropertyChanged
in the setter The property in question is bound to a textbox text property. When theFacility
value is updated in theFCalc
class the textbox is not updated. TheNotifyPropertyChanged
event is fired but when I get back to the form the values between theFacility
object and the textbox are different. To try and force this through I have used the ReadValue on the DataBinding but this does not help.txtROE.DataBindings[0].ReadValue();
I have tested the values of the textbox and the object directly after ReadValue() and they are different. Any suggestions are welcome
Never underestimate the power of human stupidity RAH
-
Hmm.... Are you certain the Facility object is not re-instantiated somewhere after the binding. That could explain this behaviour.
That was my first thought and no it is not. My second was to chase down any ref/value issues when passing an object. Also by checking the values at both ends of the binding after the ReadValue() I am know the binding is still valid.
Never underestimate the power of human stupidity RAH
-
Nothing springs to mind but I found Bind Better with INotifyPropertyChanged[^], don't know if it helps/applies in your situation.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.
Thanks but this looks like a wrapper around INotify to make it apply generically, useful in it's own right by not in this case!
Never underestimate the power of human stupidity RAH
-
That was my first thought and no it is not. My second was to chase down any ref/value issues when passing an object. Also by checking the values at both ends of the binding after the ReadValue() I am know the binding is still valid.
Never underestimate the power of human stupidity RAH
bizarre situation indeed... I know I'm pointing out the obvious here, but anyways you never know where you could have overlooked something. Are you certain the NotifyPropertyChanged event is called with the correct Property name perhaps there is a casing error?
public int MyProp
{
get{return _myProp;}
set
{
_myProp = MyProp value; //sorry was too fast posting here :)
NotifyPropertyChanged("MyProp"); //ok
NotifyPropertyChanged("myProp"); // not ok... no error but propertychanged will not be forwarded to controls...
}
}
#region INotifyPropertyChanged Membersprotected void NotifyPropertyChanged(String propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (null != handler) handler(this, new PropertyChangedEventArgs(propertyName)); } #endregion
-
bizarre situation indeed... I know I'm pointing out the obvious here, but anyways you never know where you could have overlooked something. Are you certain the NotifyPropertyChanged event is called with the correct Property name perhaps there is a casing error?
public int MyProp
{
get{return _myProp;}
set
{
_myProp = MyProp value; //sorry was too fast posting here :)
NotifyPropertyChanged("MyProp"); //ok
NotifyPropertyChanged("myProp"); // not ok... no error but propertychanged will not be forwarded to controls...
}
}
#region INotifyPropertyChanged Membersprotected void NotifyPropertyChanged(String propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (null != handler) handler(this, new PropertyChangedEventArgs(propertyName)); } #endregion
I did check before I exclaimed, of course it is spelt correctly. Besides the bloody thing is auto generated code so I would have fallen of the chair if it was wrong.
Never underestimate the power of human stupidity RAH