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

Add new row automaticaly after tab or enter in last column and last row

Thread ID:

Created:

Updated:

Platform:

Replies:

145391 Jun 19,2019 08:03 PM UTC Apr 20,2020 08:36 AM UTC WinForms 6
loading
Tags: SfDataGrid
Matthew
Asked On June 19, 2019 08:03 PM UTC

I want to add a new row automatically after user try's to tab or hit the enter key when they are in the last column of the last row in a SfDataGrid.

Thanks!

Jagadeesan Pichaimuthu [Syncfusion]
Replied On June 20, 2019 06:08 AM UTC

Hi Matthew, 
  
Thank you for using Syncfusion controls. 
  
You can able to achieve your requirement by overriding the RowSelectionController class if the SelectionUnit as Row, otherwise you have to overriding the CellSelectionController class. 
  
Please refer the below code for Row selection, 
  
sfDataGrid.SelectionUnit = SelectionUnit.Row; 
sfDataGrid.SelectionController = new RowSelectionControllerExt(sfDataGrid); 
  
public class RowSelectionControllerExt : RowSelectionController 
{ 
     SfDataGrid sfDataGrid; 
  
     public RowSelectionControllerExt(SfDataGrid sfDataGrid) 
         : base(sfDataGrid) 
     { 
         this.sfDataGrid = sfDataGrid; 
     } 
  
     protected override void ProcessEnterKey() 
     { 
         AddingNewRow(); 
         base.ProcessEnterKey(); 
     } 
  
     protected override voidProcessArrowKeysForSingleMultipleSelection(KeyEventArgs args) 
     { 
         if (args.KeyCode == Keys.Tab) 
             AddingNewRow(); 
         base.ProcessArrowKeysForSingleMultipleSelection(args); 
     } 
  
     private void AddingNewRow() 
     { 
         if (DataGrid.RowCount - 1 == DataGrid.CurrentCell.RowIndex && DataGrid.ColumnCount - 1 == DataGrid.CurrentCell.ColumnIndex) 
         { 
             sfDataGrid.View.AddNew(); 
             sfDataGrid.View.CommitNew(); 
         } 
     } 
} 
  
Please refer the below code for Cell or Any selection 
  
sfDataGrid.SelectionUnit = SelectionUnit.Cell; 
sfDataGrid.SelectionController = new CellSelectionControllerExt(sfDataGrid); 
  
public class CellSelectionControllerExt : CellSelectionController 
{ 
    SfDataGrid sfDataGrid; 
  
    public CellSelectionControllerExt(SfDataGrid sfDataGrid) 
        : base(sfDataGrid) 
    { 
        this.sfDataGrid = sfDataGrid; 
    } 
  
    protected override void ProcessEnterKey() 
    { 
        AddingNewRow(); 
        base.ProcessEnterKey(); 
    } 
  
    protected override voidProcessArrowKeysForSingleMultipleSelection(KeyEventArgs args) 
    { 
        AddingNewRow(); 
        base.ProcessArrowKeysForSingleMultipleSelection(args); 
    } 
  
    private void AddingNewRow() 
    { 
        if (DataGrid.RowCount - 1 == DataGrid.CurrentCell.RowIndex && DataGrid.ColumnCount - 1 == DataGrid.CurrentCell.ColumnIndex) 
        { 
            sfDataGrid.View.AddNew(); 
            sfDataGrid.View.CommitNew(); 
        } 
    } 
} 
  
 
Let us know whether this helps also if you need any further assistance on this.  
 
Regards, 
Jagadeesan

Matthew
Replied On April 16, 2020 06:56 PM UTC

I want to do two things is SfDataGrid, winform, C#
  1. Add a new row automaticaly after user hit's the tab or enter key when they are in the last column and last row of SFDataGrid.
  2. AND I want to enter key to function as a tab key for ALL cells & rows in SFDataGrid
Jagadeesan Pichaimuthu [Syncfusion] answered how to do part 1 above (add new row if you hit enter/tab key in last column and row of SFDataGrid and know I need to do how to both #1 AND #2 not just #1

I am attaching a zip of my source code file

See code in RowSelectionControllerExt.cs which does Request #1 but not #2
New selection controler is set in Form1_load()
sfDataGrid1.SelectionController = new RowSelectionControllerExt(sfDataGrid1); 


Thanks!



Attachment: v2_get_value_by_row_column_44264d85.7z

Susmitha Sundar [Syncfusion]
Replied On April 17, 2020 12:43 PM UTC

Hi Matthew, 

Thank you for the update. 

You can achieve your by overriding the HandleKeyOperations method in RowSelectionController.cs. Please refer the below KB document. 



Please check the sample and let us know if you need further assistance on this. 

Regards, 
Susmitha S 


Matthew
Replied On April 17, 2020 02:41 PM UTC

I want to do two things is SfDataGrid, winform, C#
  1. Add a new row automaticaly after user hit's the tab or enter key when they are in the last column and last row of SFDataGrid.
  2. AND I want to enter key to function as a tab key for ALL cells & rows in SFDataGrid
Jagadeesan Pichaimuthu [Syncfusion] answered how to do part 1 above (add new row if you hit enter/tab key in last column and row of SFDataGrid and know I need to do how to both #1 AND #2 not just #1

I am attaching a zip of my source code file

See code in RowSelectionControllerExt.cs which does Request #1 but not #2
New selection controler is set in Form1_load()
sfDataGrid1.SelectionController = new RowSelectionControllerExt(sfDataGrid1); 


Thanks!



Attachment: v2_get_value_by_row_column_44264d85.7z

Thanks!

Almost done....In the sample code you sent me, The FIRST time you hit enter or tab in last row, It add's a new row to the SfDataGrid BUT if you just put values in that new row column 1, then column 2, then hit enter after data entry into column 2 on this new last row...Nothing happens...It does not create a 2nd new row and I need it to create a 2nd new row etc..

I want user to be able to do fast continous input into the SfDataGRid and we are almost done just need that one more little piece of logic/code.

I appreciate the help.

Matthew
Replied On April 17, 2020 10:28 PM UTC

FYI,

I figured out the final part I needed. Thanks again for the help. Consider this closed please.


Susmitha Sundar [Syncfusion]
Replied On April 20, 2020 08:36 AM UTC

Hi Matthew, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Susmitha S 


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