When BindingSourceRefresh isn't helpful

When BindingSourceRefresh isn't helpful

Old forum URL: forums.lhotka.net/forums/t/6697.aspx


msk posted on Sunday, March 29, 2009

I believe I may have stumbled across the underlying reason why BindingSourceRefresh is required. 

The background to my problem is this:

Default databinding in Windows Forms triggers a read of all properties except the one you have edited/are editing.  I think I remember Rocky writing of it as a 'quirk' and perhaps hinting that it may be a bug.  So when you have a business object property that changes values entered, thoses changes are only reflected in the UI once you have edited another property.  To workaround this annoyance the BindingSourceRefresh control was created.  It hooks into the databinding events and forces the UI to update once databinding has updated the property in the bound object. 

Databinding has two modes:

1) OnValidation - Updates the bound business object when you leave a textbox. 

2) OnPropertyChanged - Updates the bound business object when you change its text

I recently encountered two situations using BindingSourceRefresh and OnPropertyChanged databinding when BindingSourceRefresh isn't helpful:

1) If your property changed the data entered the cursor jumps back to the start - feels like April Fools Day!  Example: the business object property converts strings to uppercase. 

2) If you have formatting enabled - perhaps using commas to seperate the thousands

Try my attached sample to see this in operation.  Just type 123456789 in the first textbox and abcdefg into the second. 

I came up with a few possible solutions and some thoughts:

Perhaps this is the reason for the 'quirk'?

Has anyone else experienced these issues?

It would be nice to hear of any better solutions anyone has. 

Copyright (c) Marimer LLC