Hi
When a UltraTextEditor is bound via its Value property to a nullable type, highlighting the text in the control and pressing delete will cause the bound property to be set to null. However, if the UTE is bound via its Text property instead, clearing the text results in an "Input string was not in correct format" message. I'm guessing that's because in this case the control is trying to set the bound property to a zero length string rather than null *. Is there anyway to change this behaviour so that clearing the text sets the bound property to null?
I know that we could just use the Value property, but we have used the formatting in the Advanced option under databindings to set the text to have a currency format (because our fussy users can't get on with the currency editor) and that formatting only works if you bind to the Text property, it doesn't do anything if the data is bound to the Value property of the UTE.
(* the attached example shows that clearing a UTE's contents will result in a null or an empty string depending on whether the control is bound via its Value or Text respectively)
Hi Tom,
There are two ways you could handle this. Both approaches are similar and allow you to intercept and change the value as it transitions between the Control and the data source. One is to handle the Parse event of the Binding, the other is to use a DataFilter.
I think in this case, the Parse event would be a lot easier.
It's a little bit trickier, since you are binding at design-time in your sample. But basically, you could do something like this in the Form_Load event:
Dim b As Binding = Me.UltraTextEditor3.DataBindings(0) AddHandler b.Parse, AddressOf Me.b_Parse
And then you just need the event handler to convert empty strings into Nothing:
Public Sub b_Parse(sender As Object, e As ConvertEventArgs) If String.IsNullOrEmpty(e.Value.ToString()) Then e.Value = Nothing End If End Sub
Hi Mike
That's works perfectly, many thanks. It does seem like it would be good if the UTE had a setting baked in that controlled what was written when the contents of the editor are cleared.
For info and to assist anyone else who hits this issue: We baked this functionality into the base control that all of our controls inherit from so that we didn't have to wire this up manually every time. We have a loop in our base control that loops the controls collection, finds any instances of text editors and adds the handler above to them.