Hi,
I have a XamDataGrid. Here is my Field Layout setting code.
<Style TargetType="igEditors:XamTextEditor" x:Key="paramNameStyle"> <Setter Property="ValueConstraint"> <Setter.Value> <igEditors:ValueConstraint MaxLength="50"/> </Setter.Value> </Setter> </Style>
<igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields>
<igDP:Field Name="Parameter_Name"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="True" EditorStyle="{StaticResource paramNameStyle}" /> </igDP:Field.Settings>
</igDP:Field> <igDP:Field Name="Data_Type"> <igDP:Field.Settings> <igDP:FieldSettings /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Data_Double"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="True" /> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout.Fields> </igDP:FieldLayout></igDP:XamDataGrid.FieldLayouts>
For the column "PARAMETER_NAME" I want to set regular expression so that it accepts everything apart from these values "><&;|%\n". I want to restrict these characters.
For the column "Data_Type I want to set regular expression so that it acceps only numbers and '-' (regex [0-9-] )
For the column "Data_Double" I want to set regular expression so that it acceps only numbers and '-' and '.' (regex [0-9.-] )
How can I set this condition in my xaml for these columns ?
Thanks
Arpita
Hello Arpita,
In teh sample I attached you before, I showed you how to restrict the user to enter "<". For the ">" the logic is the same, you just need to modify the condition in the "If" statement. As for the Error message, you can use the code I suggested you, wherever you need to and the text will change.
Hope this helps you.
I saw your solution . I tried it but I am not able to restrict greater than (>) and less than (<) symbols . I am not able to find any key for this thing. Can you please suggest how to restrict those ? if I use Keyboard.IsKeyDown(Key.LeftShift) it does not allow to enter any characters which requires left shift to print. I just want to restrict > and < . For restricting !, & i found key combinations eg: (Keyboard.IsKeyDown(Key.LeftShift) && e.Key == Key.D7) -- this will restrict ampersand. I want similar combination for < and > but not able to find .. Can you please help with this ?
Other question
I want to customize my message based on every condition in your solution you have defined this condition on load. Again it can have at max one customized message.
I have created a sample project for you with the functionality you want. Basically I handled the XamTextEditor’s PreviewMouseLeftButtonDown event in order to handle it if specific keys are pressed. As for the Message text, I used the XamEditors’ Resource Strings. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Ok. I tried some different pattern and it worked .
But I have some different question now.
First Question
1) Whenever I type some character which does not match my regex pattern and move out of cell I get this message "Value does not match the required pattern". I want to customize this message. How can this be done?
Second Question
2) Is there any other way where I cannot even type these chaarcters (< > ; | % & \n). Right now with this RegexPattern approach we can type these characters and after that the validation happens when we move out of cell and it displays error message. I dont want user to type these characters in first place in my cell.
The RegexPattern I gave you was an example, which you can use as guidance in order to achieve your goal. Also I can say that the one you use is not the same as the one I suggested you.