I'm trying to use a RadMaskedNumericInput inside a RadGridView cell edit template. The main issue is that when I press return, the cell edit is not committed, ie, it just does nothing.
Previously we used a RadMaskedTextBox which accepts the enter keypress for committing the cell edit.
Is there a way to get the RadMaskedNumericInput to accept Enter to commit the cell edit? Shouldn't this just happen out of the box?
We would like to be able to use the numeric input over the masked text box, but there are just too many deficiencies in its behaviour so far.
11 Answers, 1 is accepted
It is indeed better to use the new MaskedInput controls instead of the RadMaskedTextBox control and this is why I'm sorry to hear that you've encountered issues with them. And this is why I want to encourage you to take advantage of the support ticketing system when encountering such issues, as it will allow us to assist you in overcoming them in a timely manner.
So let me get straight to your question - the 'enter' key issue is a bug and it is logged in our PITS where you can track its progress. We will do our best to fix it as soon as possible. But in the meantime you can implement a sample workaround by handing the RadMaskedNumericInput.KeyDown event and commit the RadGridView.Cell changes as soon as the Enter key is hit:
public
MainPage()
{
InitializeComponent();
this
.AddHandler(RadMaskedNumericInput.KeyDownEvent,
new
KeyEventHandler(OnKeyDown),
true
);
}
private
void
OnKeyDown(
object
sender, KeyEventArgs e)
{
if
(e.Key == Key.Enter)
{
e.Handled =
true
;
myGridView.CommitEdit();
}
}
Please give this a try and let us know if it helps or if you have more issues/questions.
Regards,
Tina Stancheva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Hi Sam,
In addition to the previous post I can share my experience with the MaskedInput controls when they are placed inside CellEditTemplates.To force the controls behave like common gridviewcells when pressing keys like Enter, Right (Left, Up, Down) arrows I came up with the following:
private
void
MaskedInput_KeyDown(
object
sender, KeyEventArgs e)
{
RadMaskedInputBase mib = sender
as
RadMaskedInputBase;
if
(e.Key == Key.Right)
{
if
(mib.SelectionStart == mib.Text.Length)
SendCommandsToGridView(myGridView, RadGridViewCommands.MoveRight);
}
else
if
(e.Key == Key.Left)
{
if
(mib.SelectionStart == 0)
SendCommandsToGridView(myGridView, RadGridViewCommands.MoveLeft);
}
else
if
(e.Key == Key.Up)
SendCommandsToGridView(myGridView, RadGridViewCommands.MoveUp);
else
if
(e.Key == Key.Down)
SendCommandsToGridView(myGridView, RadGridViewCommands.MoveDown);
else
if
(e.Key == Key.Enter)
SendCommandsToGridView(myGridView, RadGridViewCommands.MoveNext);
}
void
SendCommandsToGridView(RadGridView grid, ICommand whereToMoveCommand)
{
grid.PendingCommands.Add(whereToMoveCommand);
grid.PendingCommands.Add(RadGridViewCommands.SelectCurrentUnit);
grid.PendingCommands.Add(RadGridViewCommands.BeginEdit);
grid.ExecutePendingCommand();
}
Also to overcome some validation issues (I'm using WCF RIA services and DataAnnotations for validating properties) I had to set some properties for MaskedInput controls other than their defaults... Here is an example:
<
telerik:RadMaskedTextInput
Value="{Binding DeclarationNumber,
Mode
=
TwoWay
,
ValidatesOnExceptions
=
False
,
ValidatesOnDataErrors
=
False
,
NotifyOnValidationError
=
False
,
ValidatesOnNotifyDataErrors
=
False
}"
Mask
=
"#########/####/######"
UpdateValueEvent
=
"LostFocus"
AllowInvalidValues
=
"True"
IsClearButtonVisible
=
"False"
IsLastPositionEditable
=
"False"
SelectionOnFocus
=
"SelectAll"
SectionsNavigationMode
=
"None"
HorizontalAlignment
=
"Stretch"
Padding
=
"2"
KeyDown
=
"MaskedInput_KeyDown"
/>
Hope this helps.
Got back to 0507 hotfix and everything works fine...
I prepared a sample solution trying to reproduce the issue. But I feel I might be missing something because I wasn't able to. Can you take a look at the solution I attached and let me know if it works for you or how it has to be modified to reproduce the issue? Thank you in advance.
All the best,
Tina Stancheva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I can't upload files so could you take a look at the solution located here ?
issue #1
- click on the insert new row panel
- press the enter key to accept a default datetime value for the first field
- change the value to the correct one (today's date)
- press the enter key again and notice that you can't leave the field by pressing keys, but you can easily leave it with a mouse click on any other cell...
issue #2
- select the decl weight column (don't enter the edit mode) and type the value of 1
- press the enter key and notice that the value reverted to the previous one as if AllowInvalidValues is false, but it is true...
issue #3
- select the decl weight column (enter the edit mode) and type the value of 1
- press the enter key and notice that the cell shows a validation error but you can edit another cell. If you used a common textbox as the editting control for the cell it would not allow to lose focus untill you correct the value to a valid one... It would be the expected behaviour.
Thanks.
Thank you for sending a sample solution and posting elaborate steps to reproduce all issues. However, as we will need more time to investigate them, I will keep you posted on the progress.
All the best,
Tina Stancheva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Just to follow up on this, I wanted to let you know that in order to get over the first and the third issue, you need to remove the MaskedInput.UpdateValueEvent settings from the RadMaskedInput definitions and instead define in the DataMemberBinding property binding UpdateSourceTrigger to Explicit.
As for the second issue, it a known bug caused by the RadGridView.EditTriggers default settings. Basically when the EditTriggers is set to Default or TextInput, the RadMaskedInput controls consider the first entered key as simply entering an edit mode and this is why their value starts changing only after entering another character. This issue is logged in our PITS where you can track its progress.
I updated the solution you sent to demonstrate how to modify the definitions of the controls to get over the described issues.
Regards,
Tina Stancheva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Thank you very much!
I have similar problem like below
As for the second issue, it a known bug caused by the RadGridView.EditTriggers default settings. Basically when the EditTriggers is set to Default or TextInput, the RadMaskedInput controls consider the first entered key as simply entering an edit mode and this is why their value starts changing only after entering another character. This issue is logged in our PITS where you can track its progress.
any idea when it will be resolved?
There is a workaround which uses events in code behind, for example like so:
private
void
RadMaskedNumericInput_GotFocus(
object
sender, System.Windows.RoutedEventArgs e)
{
RadMaskedNumericInput numeric = sender
as
RadMaskedNumericInput;
double
? currVal = numeric.Value;
numeric.Value = 123d;
numeric.Value = currVal;
}
Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.