I haven't really done a two way binding project before, so this might be a simple question.
I have an business object with all the right interfaces (INotifyPropertyChanged, etc...). I bound a Int32 property called CPP to a textbox named txtCPP via a BindingSource. The rules state that if CPP is less than 0, the text box should be blank, otherwise should display a value.
So to make that happen, I changed the property from Int32 to Int32? (nullable) and when the backing variable of the CPP property is less than zero, I actually return null.
This actually works fine with the UI. The problem comes when I want to persist the business object to the database. An external method takes the business object, reads its properties (including CPP) and persists them to the database. And obviously, instead of CPP being -1, it is being written as null.
I am sure I am not the first person to come up with this issue when doing two-way binding projects. How does one typically handle these problems in a clean way without polluting the form code with edge cases like that?