Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. NotifyPropertyChanged and ReadValue() not working

NotifyPropertyChanged and ReadValue() not working

Scheduled Pinned Locked Moved C#
visual-studiohelpquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mycroft Holmes
    wrote on last edited by
    #1

    I'm using VS 2008 From a form I pass a class (Facility) to another class (FCalc) in the instantiator Facility is a partial class and has the properties with NotifyPropertyChanged in the setter The property in question is bound to a textbox text property. When the Facility value is updated in the FCalc class the textbox is not updated. The NotifyPropertyChanged event is fired but when I get back to the form the values between the Facility 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

    H M G 3 Replies Last reply
    0
    • M Mycroft Holmes

      I'm using VS 2008 From a form I pass a class (Facility) to another class (FCalc) in the instantiator Facility is a partial class and has the properties with NotifyPropertyChanged in the setter The property in question is bound to a textbox text property. When the Facility value is updated in the FCalc class the textbox is not updated. The NotifyPropertyChanged event is fired but when I get back to the form the values between the Facility 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

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • M Mycroft Holmes

        I'm using VS 2008 From a form I pass a class (Facility) to another class (FCalc) in the instantiator Facility is a partial class and has the properties with NotifyPropertyChanged in the setter The property in question is bound to a textbox text property. When the Facility value is updated in the FCalc class the textbox is not updated. The NotifyPropertyChanged event is fired but when I get back to the form the values between the Facility 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

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • M Mycroft Holmes

          I'm using VS 2008 From a form I pass a class (Facility) to another class (FCalc) in the instantiator Facility is a partial class and has the properties with NotifyPropertyChanged in the setter The property in question is bound to a textbox text property. When the Facility value is updated in the FCalc class the textbox is not updated. The NotifyPropertyChanged event is fired but when I get back to the form the values between the Facility 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

          G Offline
          G Offline
          GDavy
          wrote on last edited by
          #4

          Hmm.... Are you certain the Facility object is not re-instantiated somewhere after the binding. That could explain this behaviour.

          M 1 Reply Last reply
          0
          • G GDavy

            Hmm.... Are you certain the Facility object is not re-instantiated somewhere after the binding. That could explain this behaviour.

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            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

            G 1 Reply Last reply
            0
            • H Henry Minute

              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.

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • M Mycroft Holmes

                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

                G Offline
                G Offline
                GDavy
                wrote on last edited by
                #7

                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 Members

                    protected void NotifyPropertyChanged(String propertyName)
                    {
                        PropertyChangedEventHandler handler = PropertyChanged;
                        if (null != handler)
                            handler(this, new PropertyChangedEventArgs(propertyName));
                    }
                    #endregion
                
                M 1 Reply Last reply
                0
                • G GDavy

                  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 Members

                      protected void NotifyPropertyChanged(String propertyName)
                      {
                          PropertyChangedEventHandler handler = PropertyChanged;
                          if (null != handler)
                              handler(this, new PropertyChangedEventArgs(propertyName));
                      }
                      #endregion
                  
                  M Offline
                  M Offline
                  Mycroft Holmes
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups