How to handle KeyPress Event in Radgrid for RadTextBoxEditor that validate Numeric | Text validation

4 posts, 0 answers
  1. Dipan
    Dipan avatar
    7 posts
    Member since:
    Mar 2011

    Posted 17 Feb 2013 Link to this post

    Need validation for gridview textbox when cell value changing want to handle Validation for Numeric.

    -Thank you.
  2. Plamen
    Admin
    Plamen avatar
    132 posts

    Posted 20 Feb 2013 Link to this post

    Hello Dipan,

    Thank you for writing.

    You can validate data by handling CellValidating event which is raised by RadGridView, when the current cell changes or when the cell loses input focus (when pressing Enter key). Canceling this event prevents the user from exiting the cell until a valid editor value is entered or the edit process is canceled. You can review our help article about data validation.

    Alternatively, you could use the predefined GridViewDecimalColumn or GridViewMaskBoxColumn instead. GridViewDecimalColumn allows decimal data to be displayed and edited. GridViewDecimalColumn can be bound to fields of any numeric type. Another solution might be GridViewMaskBoxColumn, which allows restricted editing of text data.

    In addition, you could read this blog post and this code library article about implementing IDataErrorInfo in RadGridView.

    I hope this helps.

    Greetings,
    Plamen
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. Visakh
    Visakh avatar
    9 posts
    Member since:
    Oct 2018

    Posted 04 Apr in reply to Plamen Link to this post

    I want allow only hexadecimal number in GridViewMaskBoxColumn, i have tried giving MaskType as Regex, and mask as [0-9a-fA-F] which is working in normal c# program, but not working for this case? Could you please help me how to achieve this? 
  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3903 posts

    Posted 08 Apr Link to this post

    Hello, Visakh,  

    I have tested a GridViewMaskBoxColumn with the specified regex and it seems to behave the same way was as a RadMaskedEditBox. I would like to note that the value is evaluated when the cell is being validated, not with each key pressed.

    I have researched in general programming forums about the proper expression for matching hexadecimal numbers. Please refer to the following threads that I believe will be helpful for your case:
    https://stackoverflow.com/questions/9221362/regular-expression-for-a-hexadecimal-number 

    https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch06s02.html

    In addition, regular expressions are usually tricky to pick up the proper expression that you need. That is why I would recommend you to test the potential regular expression  before using it. There are quite a lot of online RegEx testers that may be suitable for you: https://www.regextester.com/  

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top