I have a wpf DataGrid which only excepts integers so i have done RowValidation on it. By adding the rule like this:
this is my rule:
public class InputValidationRule : ValidationRule
/// Validates the proposed value.
/// <param name="value">The proposed value.</param>
/// <param name="cultureInfo">A CultureInfo.</param>
/// <returns>The result of the validation.</returns>
/// Checking for Alphabetical Input and Generating Validation Error if found
public InputValidationRule(DATEdit obj)
calledBy = obj;
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
bool ok = true;
String mistake = "";
if (value != null)// Method called for every row
//(value as BindingGroup).
DataRowView a = (value as BindingGroup).Items as DataRowView;
DataRow b = a.Row;
foreach (object s in b.ItemArray) //Loop for every column
if (s != b.ItemArray)
String q = s.ToString();
if (s.ToString() != "")
bool t = double.TryParse(s.ToString(), out proposedValue);
mistake = s.ToString();
ok = false;
// MessageBox.Show("Error: Input Can ");
DATEdit.gridRowEdit = false;
DATEdit.fl = true;
MessageBox.Show("ERROR: Invalid Input", "Input Error", MessageBoxButton.OK, MessageBoxImage.Error);
return new ValidationResult(false, mistake + " is not a number.");
return new ValidationResult(true, null);
whats happening is that when i select a cell and press any keyboard key it dsoes not edit it but when i double click the cell only then the cell goes in edit mode and accepts the keyboard input. But initally when i run the application it works fine and
accepts keyboad input if the cell is selcted using one click and keyboard input is given the contents of the cell will get updated. but not after when i give the first invalid value only then this starnge behaviour happens.
i want that after showing error in message box the input should revert back to its orginal value that it was before editing. So in LostFocus event of the grid i did this because only using cancel edit wont show the orignal value i had to do BeginEdit .
But this problem is not being caused by that code because i comment the lostfocus code and still its happenin
please note that I have made t.he grid using code behing not xamlRead more...