I want to lose focus and keep e.OldValue if cell is not valid in CellValidating event. Similar behavior to pressing ESC.
I wrote this code:
My column has float? datatype. It works with digits, but throws an exception, when I write some letters.
How can I achieve the desired functionality?
I wrote this code:
private
object
_cachedOldValue;
private
bool
_isValidValue;
private
void
radGridViewIssues_CellValidating(
object
sender, CellValidatingEventArgs e)
{
_isValidValue =
true
;
RadGridView radGridView = sender
as
RadGridView;
if
(radGridView ==
null
|| !radGridView.IsInEditMode)
{
return
;
}
ValidationResult validationResult = _presenter.ValidateCurrentValue(e.Column.Name, e.Value);
if
(!validationResult)
{
_isValidValue =
false
;
_cachedOldValue = e.OldValue;
}
}
private
void
radGridViewIssues_CellValidated(
object
sender, CellValidatedEventArgs e)
{
RadGridView radGridView = sender
as
RadGridView;
if
(radGridView ==
null
)
{
return
;
}
if
(!_isValidValue)
{
radGridView.CurrentCell.Value = _cachedOldValue;
}
}
How can I achieve the desired functionality?