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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Deleting new row

Thread ID:

Created:

Updated:

Platform:

Replies:

150580 Jan 12,2020 09:14 AM UTC Jan 15,2020 12:38 PM UTC WinForms 3
loading
Tags: SfDataGrid
Tom Krieg
Asked On January 12, 2020 09:14 AM UTC

I've looked at your advice to someone else about deleting a new row and refreshing the sfdatagrid. I've converted your code to Visual Basic as fiollows:
Private Sub sfDataGrid_CurrentCellKeyDown(ByVal sender As Object, ByVal e As CurrentCellKeyEventArgs)
    If Me.sfDataGrid.IsAddNewRowIndex(Me.sfDataGrid.CurrentCell.RowIndex) AndAlso e.KeyEventArgs.KeyCode = Keys.Escape AndAlso sfDataGrid.View.CurrentAddItem IsNot Nothing Then
        If Me.sfDataGrid.CurrentCell.IsEditing Then Me.sfDataGrid.CurrentCell.EndEdit(True)
        Dim gridModel = ReflectionHelper.GetProperty(GetType(SfDataGrid), "GridModel").GetValue(sfDataGrid, Nothing)
        Dim addNewRowController = ReflectionHelper.GetProperty(gridModel.[GetType](), "AddNewRowController").GetValue(gridModel, Nothing)
        Dim cancelAddNewMethod = ReflectionHelper.GetMethod(addNewRowController.[GetType](), "CancelAddNew")
        ReflectionHelper.Invoke(cancelAddNewMethod, addNewRowController, New Object() {})
    End If
End Sub

I keep getting compiler errors on ReflectionHelper. Can you please tell me what namespace this class is in? Looking at Microsoft's website I see this is no longer supported and I can't find the namespace they quote. I need to include the namespace in my form.

Saravanan Ayyanar [Syncfusion]
Replied On January 13, 2020 12:48 PM UTC

Hi Tom, 
 
Thank you for using Syncfusion  controls. 
 
We have checked your provided code example. You can use the type ReflectionHelper from the Syncfusion.WinForms.Core.Utils namespace. Please refer the below code snippet. 
 
Imports Syncfusion.WinForms.Core.Utils 
 
Private Sub SfDataGrid1_CurrentCellKeyDown(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.CurrentCellKeyEventArgs) 
        If Me.sfDataGrid1.IsAddNewRowIndex(Me.sfDataGrid1.CurrentCell.RowIndex) AndAlso e.KeyEventArgs.KeyCode = Keys.Escape AndAlso sfDataGrid1.View.CurrentAddItem IsNot Nothing Then 
              If Me.sfDataGrid1.CurrentCell.IsEditing Then 
                    Me.sfDataGrid1.CurrentCell.EndEdit(True) 
              End If 
              Dim gridModel = ReflectionHelper.GetProperty(GetType(SfDataGrid), "GridModel").GetValue(sfDataGrid1, Nothing) 
              Dim addNewRowController = ReflectionHelper.GetProperty(gridModel.GetType(), "AddNewRowController").GetValue(gridModel, Nothing) 
              Dim cancelAddNewMethod = ReflectionHelper.GetMethod(addNewRowController.GetType(), "CancelAddNew") 
              ReflectionHelper.Invoke(cancelAddNewMethod, addNewRowController, New Object() { }) 
 
        End If 
 
 
Please let us know, if you require further assistance on this. 
 
Regards, 
Saravanan A. 


Tom Krieg
Replied On January 14, 2020 06:04 AM UTC

Thank you for that. The code runs through without error and I checked with the debugger and everything executes properly. Problem is ... the new line is still visible.
Here's the scenario ... empty sfdatagrid. Allow add new row = true, the add new row text = "Click to add new row" and the new row position is at the end of exisitng data.

User clicks "Add new row" and the new row is created and focus is on the first cell.
User starts typing and realises he has made a right royal mess of the whole line and wants to cancel.
User presses ESCape key.
The code executes and the new row is cancelled.
The new row is still shown, but is blank.

Can the new row just "disappear" and the "Click here..." text shown instead?

The user has to up-arrow to get rid of the new row.

Vijayarasan Sivanandham [Syncfusion]
Replied On January 15, 2020 12:38 PM UTC

Hi  Tom Krieg, 
 
Thanks for the update. 
 
We have replicated your scenario based on the provided information. And the addnew row text is not shown since the selection is maintained in that row. However, you can make the addnewrow text visible, by clearing selection as like below code snippet, 
  
Code snippet:   
  
 
Imports Syncfusion.WinForms.Core.Utils
 
Private Sub SfDataGrid1_CurrentCellKeyDown(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.CurrentCellKeyEventArgs) 
        If Me.sfDataGrid1.IsAddNewRowIndex(Me.sfDataGrid1.CurrentCell.RowIndex) AndAlso e.KeyEventArgs.KeyCode = Keys.Escape AndAlso sfDataGrid1.View.CurrentAddItem IsNot Nothing Then 
              If Me.sfDataGrid1.CurrentCell.IsEditing Then 
                    Me.sfDataGrid1.CurrentCell.EndEdit(True) 
              End If 
              Dim gridModel = ReflectionHelper.GetProperty(GetType(SfDataGrid), "GridModel").GetValue(sfDataGrid1, Nothing) 
              Dim addNewRowController = ReflectionHelper.GetProperty(gridModel.GetType(), "AddNewRowController").GetValue(gridModel, Nothing) 
              Dim cancelAddNewMethod = ReflectionHelper.GetMethod(addNewRowController.GetType(), "CancelAddNew") 
              ReflectionHelper.Invoke(cancelAddNewMethod, addNewRowController, New Object() { })
                            this.sfDataGrid.ClearSelection();   
        End If 
 
 
Please let us know, if you need any further assistance on this.
 
Regards, 
Vijayarasan 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon