GridView Cancel AddNewRow

2 posts, 0 answers
  1. Shawn
    Shawn avatar
    4 posts
    Member since:
    Jul 2019

    Posted 11 Jan 2020 Link to this post



    I've recently added some simple data validation to my grid which are a bunch of checks that look rather like this:

    if (Convert.ToInt32(e.Row.Cells["Category"].Value) == 0)
                    e.Cancel = true;
                    e.Row.ErrorText = "Project Must have a Category";


    at the end of the rowformatting event I have this:

    if (e.Cancel)
             if (MessageBox.Show(e.Row.ErrorText, "ERROR", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                 //TODO cancel row add
                 //if (radGridView.MasterView.TableAddNewRow.IsCurrent)


    This gets the focus out of the AddRow section. However when I click on any other row, the event fires... but the row that it's referencing is still the new row data, which means that I get the error message again and again and again! How do I properly cancel the AddRow so that the gridView can return to it's default behavior?



  2. Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    4170 posts

    Posted 13 Jan 2020 Link to this post

    Hello, Shawn,

    According to the provided information, it is not very clear how exactly you setup the grid and in which event you cancel the new row. However, note that RadGridView offers the UserAddingRow event which is quite useful for handling such cases and cancelling the new row: 

    If you are still experiencing any further difficulties, it would be greatly appreciated you can provide more details about the setup on your end so I can simulate the behavior in a sample project on my end.

     I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top