C1TextBox, databinding and validation

Posted by: a.sharov on 13 January 2022, 6:01 pm EST

    • Post Options:
    • Link

    Posted 13 January 2022, 6:01 pm EST

    Hi.

    Here is sample for following problem – https://drive.google.com/file/d/1bDf8HxtLR1qgvuCZ8t-BjJZv0-o45GZA/view?usp=sharing

    When I reject postvalidation of textbox data (e.Succeeded = false), I assume that datasoruce won’t be updated, but it is updated. In sample I got to fields one for edit with errorprovider (complete or error) and second (lower text box) just binded to data source. In code I reject update (weel, I think so) but data source is still updated even error provider manifest error with red blinking.

    What I’m doing wrong?

    Thanks in advance.

  • Posted 14 January 2022, 6:43 am EST

    Hi,

    You are using the PostValidated event, it is fired after the value has been validated. So setting e.Succeeded = false has no effect here.

    You need to set the PostValidation.Validation property to PostValidationTypeEnum.PostValidatingEvent and then handle the PostValidating event instead of the PostValidation event.

    Kindly refer to the attached sample showing the same.

    Regards

    Avnish

    SuperErrorProvider_val_mod.zip

  • Posted 14 January 2022, 10:27 am EST

    Hi.

    Got it, thank you.

    Am I right that I can achieve the same behaviour with

    
    c1TextBox1.PreValidation.Validation =   PreValidationTypeEnum.PreValidatingEvent;
    
    

    and

    
    
            private void c1TextBox1_PreValidating(object sender, PreValidationEventArgs e)
            {
                var val = Convert.ToDouble(e.Text);
                var tb = (TextBox)sender;
    
                //check for required condition
                if (val >= 50)
                {
                    // e.ErrorInfo.C1SuperErrorProvider = epError;
                    SetErr(tb, "test");
                    e.Succeeded = false;
                    return;
                }
                SetOk(tb);
                e.Succeeded = true;
            }
    
    

    I guess it is more proper to use prevalidation event rather postvalidation.

  • Posted 17 January 2022, 3:10 am EST

    Hi,

    The C1TextBox parses the string input to the Data type specified in the DataType property and stores it in the Value property. The PreValidating event is fired before the String input is parsed to the Typed value and can be used to validate the raw string input. The PostValidating event is fired after the string is parsed to the Typed Value and can be used to validate the value.

    You can use the PreValidating event as well, but in your case, you need double type values to be in a range, so we suggest you use the PostValidating event.

    Regards,

    Avnish

Need extra support?

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

Learn More

Forum Channels