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

Cancel Adding of new row

1 Answer 785 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric Anderson
Top achievements
Rank 1
Eric Anderson asked on 04 Aug 2010, 10:38 PM
Hello,

We have a GridView bound to a BindingLIst of custom business objects. The customer has very strict data validation requirements and doesn't want a new row to be added to the data source until the data is clean, so we have implemented RowValidating and perform validations there for both the 'new' row and existing rows. This works well. 

The problem is that if a user decides against adding the row, they can't simply click out of the row, they would either have to finish the row entry and then delete the row, or close out of the form and then return to it. These are not elegant solutions. We wish to provide a Cancel button that will simply discard all changes made to the row, be it a 'new' row or an existing row. How can we accomplish this?

Thanks

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 10 Aug 2010, 07:43 AM
Hello Eric Anderson,

Thank you for writing.

In general the end user can cancel adding or editing a row by pressing the escape key. If the user is editing a new row, then the first escape cancels cell edit and the second one cancels the whole process of adding new row. If this behavior does not meet all your requirements, you can easily customize the behavior through adding a command column which cancels the current edit. Here is a sample snippet that implements this customization:

void radGridView1_CommandCellClick(object sender, EventArgs e)
{
    GridCommandCellElement cell = (GridCommandCellElement)sender;
    GridViewDataColumn column = (GridViewCommandColumn)cell.ColumnInfo;
    if (column.Name == "Cancel")
    {
        this.radGridView1.CancelEdit();
        this.radGridView1.MasterView.TableAddNewRow.CancelAddNewRow();
    }
}

I hope this helps. Let me know if you have any additional questions.

Kind regards,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Eric Anderson
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or