Home > C#, WPF > WPF datagrid Not allowing to edit after validation errors

WPF datagrid Not allowing to edit after validation errors

Hi,

Most common issue which has been raised frequently about wpf datagrid editing on validation errors.
Scenario to use following code is :- Whenever user enters a value which fires some validations and user try to reset data in datagrid by hitting reset or user try to rollback the data to previous state.Datagrid still remain in uneditable even after valid data has reseted for datagrid.Reason behind failure is, Datagrid maintains class level Private variable _hasCellValidation which is set whenever there are cell level validations on datagrid.Even though we try to reset data to previous state,Datagrid still remains hascellValidation = true.if it is true,it doesnot allow us to edit grid.if it if false it allows us to edit.
Following is reflection code which allows u to edit datagrid whenever validation fired up on resetting data.
Another Work Around can be Rebinding ItemSource again back to datagrid.
Im having requirement that whenever user edits datagrid cell and enters value in a datagrid
  public void ResetDatagrid()
        {
            Type DttagridType = this.GetType().BaseType;
            PropertyInfo HasCellValidationProperty = DatagridType.GetProperty("HasCellValidationError", BindingFlags.NonPublic | BindingFlags.Instance);
            if (HasCellValidationProperty != null)
            {
                HasCellValidationProperty.SetValue(this, false, null);
            }
          
        }
I didnot tested code much..Plz copy on ur risk.
WIth Regards,
Mahender
Categories: C#, WPF Tags:
  1. June 23, 2011 at 7:59 am

    Good Article

  2. March 5, 2013 at 7:13 am

    Thanks for ones marvelous posting! I really enjoyed reading
    it, you’re a great author. I will remember to bookmark your blog and will often come back in the future. I want to encourage you to continue your great writing, have a nice day!

  1. No trackbacks yet.

Leave a reply to Buy Online Cancel reply