This page describes a problem with .NET simple data binding — a property of a custom type couldn’t be bound correctly to the Text
property of a standard TextEdit, because the internal logic would never convert the string value back to the object type. A given TypeConverter
would simply be ignored in the process. The only workaround was to use the Parse
event of the Binding
object — not a nice way to go because the code wouldn’t be central to the class and its type converter any more.
While looking at the reasons behind this, I found a workaround for this in .NET 2: the FormattingEnabled
property of the Binding
object. While this is documented to do something quite different, the changed logic of the Binding.OnParse
method actually checks for this parameter and the problem doesn’t show when FormattingEnabled
is set to true for the binding. It’s possible to pass true
for this parameter right when creating the binding, like this:
textBox1.DataBindings.Add("Text", myObject, "MyProperty", true);
Now I’m still wondering if I’m missing something here… the original problem, although it seems to be as described on the NoiseEHC page, sounds so… stupid? And the small change in .NET 2, while it does the trick, doesn’t look like a purposeful fix of the issue to me. Hm.