none
Make Simple Binding to Control/Class Property Two-way? RRS feed

  • Question

  • We're using C# in VS 2005.

    We've successfully bound a DataGridView to a collection of Widget objects using the generic BindingList<Widget>, and the binding is 2-way.  I also understand we could have used another collection mechanism and implemented IBindingList.

    Now we've bound a TextBox's Text property to a custom property of a single UserControl instance, and it displays the initial property value.  However, changes to the UserControl's custom property do not get automatically reflected in the TextBox.  In other words, it appears the binding is 1-way.  Using BindingList<T> or IBindingList would seem to be overkill in this case, because we have only one instance, not a collection.

    We've found a number of sources on this subject (most dating back to VS 2003), talking about raising change notification events, and have also read a variety of help subjects including the Bindable attribute, but they have either not worked or seemed too complex to be easily reusable.  What is the easisest way (hopefully declaratively) in VS 2005 to enable 2-way binding to custom properties in UserControls (and Classes as well)?

    Thanks in advance...

    Friday, January 27, 2006 1:18 PM

Answers

  • Raising change notifications is the easiest way.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

    Friday, January 27, 2006 3:39 PM

All replies

  • Raising change notifications is the easiest way.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

    Friday, January 27, 2006 3:39 PM
  • Thanks Mark.  I've just discovered the INotifyPropertyChanged Interface (new in 2.0) which allows just one notfication event for all properties in the class.
    Friday, January 27, 2006 3:56 PM