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

[Solved] ValueChanging event on GridViewMaskedTextBoxColumn?

7 Answers 149 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
James
Top achievements
Rank 1
James asked on 03 Feb 2011, 04:50 AM
Hi,

We're trying to implement regular expression masking in the GridView the same way it's implemented elsewhere in the application where Telerik controls are used.  Usually this means handling the ValueChanging event and comparing the current text to the RegEx, then setting e.IsHandled to reflect the validity of the current character.  Is this possible to do on a per-column basis in the GridView?  I understand the GridView has a KeyDown event that can be captured, but this isn't prefereable for maintainance reasons - it would require a huge amount of code in that handler.  Is it possible to get KeyDown or Validating events on a per column basis?

Thanks!

7 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 03 Feb 2011, 10:50 AM
Hello James,

You may handle the CellValidating event of the grid and verify that the validated cell corresponds to the column you want:

private void clubsGrid_CellValidating(object sender, GridViewCellValidatingEventArgs e)
        {
            //First option
            if (e.Cell.Column.UniqueName.Equals("MyUniqueName"))
            {
                 
            }
            //Second option
            if((e.Cell.Column as GridViewDataColumn).DataMemberBinding.Path.Path == "MyProperty")
            {
 
            }
        }

Depending on your particular scenario, you may try to implement a GridViewExpressionColumn

Best wishes,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
James
Top achievements
Rank 1
answered on 04 Feb 2011, 05:40 AM
Hi Maya,

I tried using the CellValidating event and it doesn't seem to fire at the same times as the Validating event on the masked edit control.  With the mask control, the validating event fires at every keystroke.  That's a good thing for our use as it can be used to prevent unwanted keypresses.  On the other hand, the CellValidating event on the grid only fires when the cell receives or loses focus.  Is there another event I could use to get notified any time the user makes an edit?  I'd prefer not to use the KeyDown event on the grid because the code would need to filter out irrelevant keypresses such as the tab key and arrow keys.

Thanks for pointing out the Expression column.  While the column looks useful for calcualted values it doesn't seem to fit the scenario of preventing incorrect data entry.

I might also take this opportunity to urge Telerik to please create proper regular expressions in the mask controls.  Users could certainly appreciate the extra flexibility of a regex.

Thanks,
James
0
Maya
Telerik team
answered on 04 Feb 2011, 08:48 AM
Hello James,

In this case you may define the CellEditTemplate of the column and set it as RadMaskedTextBox. Thus you will be able to subscribe directly to the ValueChanging event and handle it in the code behind. 
As far as your requirements for the proper regular expressions for the mask controls, I would need a bit more details. May you specify what are the scenarios you want to cover and how do you want this to be implemented and used ?  
 

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
James
Top achievements
Rank 1
answered on 04 Feb 2011, 04:26 PM
Hi Maya, it looks like the CellTemplate will do what we need.  As for regex masking, take a look at this implementation:
http://demos.devexpress.com/DXEditorsSilverlightDemos/

The email text entry is a good example - it's a mask control with a regular expression to filter out invalid characters in an email address.  During editing the control both filters out invalid characters and shows the user that the eventual format should look like "_____@___.___".  It would be great if Telerik had something similar for use both inside and outside of the grid.  A search of these forums for "regular expressions" shows mentions of Telerik developing a regex control in 2009, unfortunately it doesn't look like that work was completed.

Thanks,
James
0
Alex Fidanov
Telerik team
answered on 07 Feb 2011, 09:52 AM
Hello James,

Currently, we do not have a built-in Regex expression validation for the RadMaskedTextBox. However, you can apply a regex expression on the MaskedText of the RadMaskedTextBox. You can use its ValueChanging event and check if the MaskedText satisfies the Regex. If it does not, you can handle the ValueChanging event (e.Handled = true) and revert to the old value. For Q1 2011, we will support the Data Annotation attributes, which provide Regex validation, with the new suite of masked input controls and you will be able to use that as well.

Greetings,
Alex Fidanov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
James
Top achievements
Rank 1
answered on 15 Feb 2011, 05:04 PM
I've run into an issue using the CellEditTemplate where the the initial value of the edit control does not match the value displayed in the Grid (initially, the edit control is always empty).  Also, after editing, the value in the edit control is not copied back to the grid.  Is it possible to manually copy these values between the controls when editing starts and completes?
0
Maya
Telerik team
answered on 21 Feb 2011, 08:44 AM
Hello James,

In order to be able to reproduce the issue you reported and provide a suitable solution, I would need a bit more information. Is a value different when in edit and when in view mode ? It would be great if you could describe in further details the case and if possible to share any relevant code-snippets.
 

Best wishes,
Maya
the Telerik team
Tags
GridView
Asked by
James
Top achievements
Rank 1
Answers by
Maya
Telerik team
James
Top achievements
Rank 1
Alex Fidanov
Telerik team
Share this question
or