This is a migrated thread and some comments may be shown as answers.

GridView Cancel AddNewRow

1 Answer 473 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 11 Jan 2020, 04:10 PM

Hi,

 

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.radGridView.MasterView.TableAddNewRow.CancelAddNewRow();
             radGridView.EndEdit();
         }
     }

 

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?

 

Thanks

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 13 Jan 2020, 11:51 AM

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: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/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. 

Regards,
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.
Tags
GridView
Asked by
Shawn
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or