This is a migrated thread and some comments may be shown as answers.

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

3 Answers 394 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dipan
Top achievements
Rank 1
Dipan asked on 17 Feb 2013, 07:08 AM
Need validation for gridview textbox when cell value changing want to handle Validation for Numeric.

-Thank you.

3 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 20 Feb 2013, 04:52 PM
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.
0
Visakh
Top achievements
Rank 1
answered on 04 Apr 2020, 09:14 AM
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? 
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Apr 2020, 11:56 AM
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.
Tags
GridView
Asked by
Dipan
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Visakh
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or