OnPropertyChanged databinding issue.

We have a binding setup from a TextBox to our business object, the binding DataSourceUpdateMode is set to OnPropertyChanged and the field we've bound to is a String type.  Our object formats the string to be all UPPER case; if we type in an upper case character everything works as expected, however, if we type in a lower case character the cursor position in the TextBox goes back to 0.

Is this working properly or is this a bug; and do you have any recommended ways for getting around this

Thank you,

Phil


Answer this question

OnPropertyChanged databinding issue.

  • kizelli

    OK, I attempted to recreate this in a simple solution:  I created a class with a description property on it, then Added a form and created a datasource, dragged the description property over two times (the description property upper cases everything).  Then i changed them to validate OnPropertyChanged (which it would be nice if this were a property on the datasource or the bindingsource so you don't have to change it on each control).  What happens is when I type the description in, it uppercases on the other control but not the one I'm typing in...  so the binding of the currently selected object isn't updating.  Is this how this is supposed to work   So when you tab off the control it is still lowercase and the other one is upper cased; or is this example just too primitive to work correctly  

    Are there any good articles written yet on proper use of the binding sources   It seems like there are many ways to accomplish the same thing.  I digress...


    Thanks again, I will look at my code in the morning and see if I'm missing something to get this to reproduce.

    Phil

  • V4Venkat

    I am using beta2, let me see if I can pull some code together that can reproduce this; we have an entire underlying framework so it might be difficult.

    Sweet, I hadn't seen that property :)  Thank you for your quick response and kudos to you and your team for a fantastic product!  Looks like our UI code will be reduced by about 80 - 90%.

  • PA

    Are you using Beta 2   I can't reproduce this but I recall seeing something like this in earlier bits.  If you are able to reproduce on Beta 2, can you attach some code that demonstrates the issue

    Also - you can set the "CharacterCasing" property on the TextBox to force all upper/lower case entry.

    Joe Stegman
    The Windows Forms Team
    Microsoft Corp.

    This posting is provided "AS IS" with no warranties, and confers no rights.


  • lianaent

    Our design is we assume the set will succeed or throw an exception.  If it is successful (doesn't throw), we assume the value has not changed and therefore don't re-read it (this is by design for performance reasons).  The second control is bound to the first data source, and picks up the value after it has been written to the data source (and turned into an upper case value).  One way you can make this work is to hook the Validated event on the TextBoxes and add the following code:


    private void nameTextBox_Validated(object sender, EventArgs e)
    {
     TextBox tb = (sender as TextBox);

     if (null != tb)
     {
      Binding b = (sender as Control).DataBindings["Text"];

      if (null != b)
      {
       b.ReadValue();
      }
     }
    }

     



    I have seen a similar request before from someone who was truncating their text value when writing it to a data source and wanted the Control to reflect the truncation.  We could provide an option on the Binding type that forced a re-read.  Please log a bug on this (http://lab.msdn.microsoft.com/productfeedback/default.aspx) and although we will probably not be able to address this in VS 2005, we will address this in our next release.

    Joe Stegman
    The Windows Forms Team
    Microsoft Corp.

    This posting is provided "AS IS" with no warranties, and confers no rights.


  • OnPropertyChanged databinding issue.