We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Cancel Row Insert

I’ve got a GridDataBoundGrid and I need to simulate the Before Insert event in Microsoft Access. To do this, I need to know when a new record is being added to the grid and have the ability to cancel the adding of the new record. I have tried using RowEditing event of the data grid, but setting e.cancel = true only cancels the text that was entered into the cell, it does not remove the row just inserted. I tried multiple variations using MyDataGrid.CurrentCell.CancelEdit, MyDataGrid.CurrentCell.EndEdit, MyDataGrid.Binder.CancelEdit, and MyDataGrid.Binder.EndEdit, but nothing gets rid of the new row. So far, the best I have come up with is set e.cancel = true and move the current cell to the previous row. Private Sub MyDataGrid_RowEditing(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridRowEventArgs) Handles MyDataGrid.RowEditing If e.IsAddNew = True Then e.Cancel = True MyDataGrid.CurrentCell.MoveTo(e.RowIndex - 1, MyDataGrid.CurrentCell.ColIndex) End If End Sub The problem with this code is that the row I moved to now is in a state of editing (the row header has the pencil icon instead of the arrow icon). Is there a way to change the row state or is there a better way to cancel the inserting of a new row?

1 Reply

AD Administrator Syncfusion Team April 26, 2006 05:35 AM UTC

Hi Chad, One simple way to cancel the inserting new row is by just sending the Esc key to the grid twice. Below is a code snippet in a button click event handler. If using the button click event to send the keys then, make sure to set the CausesValidation property of the button to False. Let us know if this helps. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.GridDataBoundGrid1.Focus() SendKeys.Send("{Esc}") SendKeys.Send("{Esc}") End Sub Regards, Calvin.

Loader.
Live Chat Icon For mobile
Up arrow icon