Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1125
Nulls in bound UltraTextEditors
posted

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)

NullStringBindingInUltraCombo.zip
Parents
  • 469350
    Verified Answer
    Offline posted

    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

Reply Children
No Data