Null value in numeric box

Posted by: mayur.purandare on 15 August 2018, 1:57 pm EST

  • Posted 15 August 2018, 1:57 pm EST

    Hello,

    I am using c1 numeric box inside a template row of c1datagrid.

    My requirement is to show the numeric box blank when null is assigned .

    However, it always shows 0 even if the value is null.

    I also have set "Allow Null" property.

    Is there any other setting has to be done?

    Thank you..
  • Replied 15 August 2018, 10:44 pm EST

    Hello Mayur,

    I am sorry but I cannot observe this behavior. At my end, just setting the AllowNull property to true makes the C1NumericBox to remain blank. See attached video showing the same.
    So, I would like to ask you what ComponentOne version are you using? If you are using any version older than 2018v2, then I would suggest you to kindly upgrade and try testing the issue using the latest version. You may download it from: http://prerelease.componentone.com/dotnet40/c1wpflibrary/2018-t2/C1WPFBasicLibrary.4_4.0.20182.595.zip

    Thanks,
    Ruchir
  • Replied 15 August 2018, 10:54 pm EST

    Thanks for the reply.
    I will check this and will get back to you.
  • Replied 15 August 2018, 10:59 pm EST

    My Component One version is 4.0.20171.549.
  • Replied 16 August 2018, 2:30 pm EST

    Hi Mayur,
    I checked the issue with 2017v1.549 also and AllowNull property seems to be working correctly at my end.
    Could you please test the attached sample at your end and share your observations.
    Regards,
    Ruchir
    TemplateRow_C1NmBx.zip
  • Replied 20 August 2018, 4:48 pm EST

    Thank you for the reply.

    Will check and get back to you.

    Regards,
    Mayur
  • Replied 22 August 2018, 10:52 pm EST

    Hello,

    Attaching a sample here with Numeric Box.

    When I select the number in numeric box within a Data Grid Row, it gives me an error. (Attaching Error Screenshot)

    Is there any way so that deleting the number is accepted without any error.

    Thank you.Demo.zip
  • Replied 23 August 2018, 5:58 pm EST

    Hello Mayur,

    Thank you for the sample. The error shown in the screen-shot is validation error.
    To hide this error message upon deleting the value, you may do any of the following:
    1. Change binding Mode for Value from TwoWay to default/OneWay
    2. Access the C1ValidationDecorator from C1NumericBox's Template and modify its Style or set its Visibility to hidden.
    Refer attached sample
    3. Or you may convert the values manually using a binding converter.

    Thanks,
    Ruchir
    Demo_modified.zip
  • Replied 23 August 2018, 6:13 pm EST

    Thank you Ruchir for the reply.

    I will check this and will get back.

    Regards,
    Mayur
  • Replied 3 September 2018, 4:51 pm EST

    Hello,

    It worked as I did not get the warning box again.

    However I have few queries --

    1. In the attached sample, when the default value of the property bound to numeric box is set to null, numeric box still displays 0.

    2. When I press delete key on the numeric box I do not get the property change notification even though binding mode is two way.

    Is this the default behaviour of box.

    Thank you.
    Demo-03-09-18.zip
  • Marked as Answer

    Replied 3 September 2018, 7:27 pm EST

    Hello Mayur,

    Thank you for sharing the application.
    Yes, both these are by-design. However, you can workaround them to meet your requirements using a Converter.
    1. For showing a blank/empty cell when C1NumericBox's value is set to null, then you need to define Convert method of IValueConverter, as follows:
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
    if (value == null)
    return double.NaN;

    return value;
    }

    2. To get notified upon pressing Delete key on C1NumericBox, you need to define IValueConverter's ConvertBack method, as follows:
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
    if(double.IsNaN(System.Convert.ToDouble(value)))
    {
    return null;
    }
    return value;
    }

    Then in XAML, sjust use this converter while binding C1NumericBox's Value.
    Attached is modified sample application for reference.

    Thank you,
    Ruchir
    Demo_fixed.zip
  • Replied 3 September 2018, 8:19 pm EST

    Hello Ruchir,

    Thanks for the reply.

    Will check this.

    Regards,
    Mayur
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels