Control validation stuck

Posted by: a.sharov on 20 January 2022, 3:39 pm EST

    • Post Options:
    • Link

    Posted 20 January 2022, 3:39 pm EST

    Hi.

    Three questions:

    1)I have problem with control validaion. Suppose that I want to browse some path, but instead I decide to enter path manually. The problem is that I can’t then switch (focsu) ot any other control, I locked on this control, so I have to enter some correct path. Other issue is that if enter this control for input and then I decide to switch to other control – same behaviour. This is very very unconvenient and unexpected behaviour. How to handle it properly? I’ve tried to make contrl readonly – same behaviour, handle manually any input? Also

    btn.Focus() in my code doesn’t work, I’m still focused on txtbox.

    What I’m doing wrong?

    https://drive.google.com/file/d/1UMeYVV-JFX5FY1HgXmBRGtXzLjiXwyEW/view?usp=sharing[img]https://gccontent.blob.core.windows.net/forum-uploads/file-0cb48b22-bcf7-4af3-8e63-c7ec0e2fb58c.png[/img]

    1. There is screen shown with “Validation error” (see attached img), how turn it off?

    2. General question, probably worth separate topic but I will ask here anyway.

      Suppose that I want to use ValidateChildren function (triggere by some button) so each control can validate itself and manifest error if any. This function raise Validating event. The problem is that this function raises when control loses focus also. So I will run some potentially heavy code at least twice. How to properly do this, is there something from c1 (grape)? The only choise I see is to subscribe to this event in some btn click event (and after unsuscribe again). I think this would work but this looks like more hack .

    
    SaveBtnClick()
    {
    
     try{
    //sub to validating events
    var isOk = ValidateChildren(ValidationConstraints.Visible);
    if (!isOk)
     {
           return;
       }
    }
    finally
    {
    
    //unsub validating events
    }
    }
    
    

    Thanks in advance.

  • Posted 21 January 2022, 7:30 am EST

    Hi,

    First, we suggest you use either the PostValidation or PreValidation provided in the C1TextBox. You can use the PostValidating event to do the same thing you are doing in the validating event. Then you use the ErrorInfo property of the C1TextBox to customize what happens if an error occurs.

    For (1), you can use the CanLoseFocus property of the ErrorInfo and set it to true to enable the control to lose focus on the error.

    For (2), you can use the ShowErrorMessage property of ErrorInfo and set it to false to avoid the error message from showing.

    For (3), as we understand you want to validate on-demand, you can use the ValidateText method of the C1TextBox to validate the contents of C1Textbox on-demand. The method will cause the text to validate just as it would on lose focus. If you meant something else, please elaborate on your use case and we will help you accordingly.

    ErrorInfo: https://www.grapecity.com/componentone/docs/win/online-input/C1.Win.C1Input.4.5.2~C1.Win.C1Input.ErrorInfo_members.html

    ValidateText: https://www.grapecity.com/componentone/docs/win/online-input/C1.Win.C1Input.4.5.2~C1.Win.C1Input.C1TextBox~ValidateText.html?highlight=validatetext%2C

    Regards

    Avnish

    ValidationStuck_mod.zip

  • Posted 21 January 2022, 12:18 pm EST

    Hi.

    Thank you for reply, 1) and 2) clear.

    1. I want to simply call ValidateChildren() and so it’s control validate itself and if needed report any error. ValidateText() forces me to call this method on any needed control by hand, if I’m not mistaken. This is very unconvenient comparing with ValidateChildren().
  • Posted 24 January 2022, 2:54 am EST

    Hi,

    The ValidateChildren method iterates through the controls and performs validation for each control. You can write a similar extension method that iterates through the controls and calls the ValidateText method of the C1 controls. Please refer to the sample attached.

    Regards

    Avnish

    ValidationStuck_all.zip

Need extra support?

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

Learn More

Forum Channels