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

RadGridView CELL Editing Validation.

1 Answer 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Karthikeyan
Top achievements
Rank 1
Karthikeyan asked on 09 Dec 2011, 10:53 AM

Hi Telerik Admin's,

I've requirement in RadGridView.
I'm adding a row dynamically in the gridview.
The added row can be edit, while editing the row I want the user to restrict to enter ONLY ALPHA NUMERIC.
Here I've pasted the code for restricting user enter special character. please have a look.
As well as, is there any possibility to do the validation in each column cell of the newly added row.

Check ALPHA NUMERIC:-
---------------------------------

     public bool IsAlphaNumeric(String strToCheck)
        {
            Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
            return !objAlphaNumericPattern.IsMatch(strToCheck);
        }

Remove Special Characters :-
--------------------------------------

 public string RemoveSpecialChars(string input)
        {
            return Regex.Replace(input, @"[^0-9a-zA-Z\._]", string.Empty);
        }

Please guide me to do this ASAP.

Thanks in advance,
Karthikeyan Manickam.

1 Answer, 1 is accepted

Sort by
0
Tyree
Top achievements
Rank 2
answered on 09 Dec 2011, 02:23 PM
I am sure you are aware that you can put your logic in the setter of the particular column in question but this may not look as nice as you want as they can type anything and only on leaving the column does the data reflect the change. Another approach is to set the UpdateSourceTrigger=Explicit on the edit control (like a textbox) and then capture the appropriate event on the control to commit the data as they type. This can work but its a bit ugly and cumbersome.

The approach I use is a custom behavior on the TextBox which basically ignores keystrokes that don't match the pattern defined. For me this has been the most trouble-free implementation. My textbox looks like:
<TextBox MaxLength="11" Text="{Binding SomeValue}">
    <i:Interaction.Behaviors>
        <behaviors:LimitKeyPressToType InputType="Numeric" AllowNegative="True" FocusBehavior="SelectAll"/>
    </i:Interaction.Behaviors>
</TextBox>
The behavior is a single class to include in your project, if you care to try it I can post the code.

You could also use Teleriks MaskedInput but I personally do not like how it looks and behaves.
Tags
GridView
Asked by
Karthikeyan
Top achievements
Rank 1
Answers by
Tyree
Top achievements
Rank 2
Share this question
or