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

AddNewRow Shortcut Key

Thread ID:

Created:

Updated:

Platform:

Replies:

149789 Dec 9,2019 03:52 PM UTC Dec 10,2019 01:22 PM UTC WinForms 2
loading
Tags: SfDataGrid
ER
Asked On December 9, 2019 03:52 PM UTC

Hi,

1.
Is there a way I can programatically create a shortcut key for the AddNewRow of SfDataGrid? 
Example, bind CTRL+N to add new row instead of clicking it.


2.
How can I programatically open a form when double-clicking a currently selected row in an SfDataGrid?


Thanks in advance.




ER
Replied On December 10, 2019 10:42 AM UTC

Hi Syncfusion Team,

No replies yet???



Gowtham Gopalsamy [Syncfusion]
Replied On December 10, 2019 01:22 PM UTC

Hi ER,   
   
Thank you for using syncfusion controls. 
 
 
Is there a way I can programatically create a shortcut key for the AddNewRow of SfDataGrid?  
You can achieve your requirement to programmatically create a shortcut key for add a new by overriding the HandleKeyOperations in CustomSelectionController. 
 
Please find the below code snippet, 
 
sfDataGrid.SelectionController = new CustomSelectionController(this.sfDataGrid); 
 
public class CustomSelectionController : RowSelectionController 
{ 
    SfDataGrid sfDataGrid; 
    OrderInfoCollection orderInfoCollection = new OrderInfoCollection(); 
 
    public CustomSelectionController(SfDataGrid sfDataGrid) 
        : base(sfDataGrid) 
    { 
        this.sfDataGrid = sfDataGrid; 
    } 
 
    protected override void HandleKeyOperations(KeyEventArgs args) 
    { 
 
        if (args.KeyCode == Keys.N && (Control.ModifierKeys == Keys.Control || Control.ModifierKeys == Keys.ControlKey 
            || Control.ModifierKeys == Keys.LControlKey || Control.ModifierKeys == Keys.RControlKey)) 
        { 
            this.sfDataGrid.View.AddNew(); 
            (this.sfDataGrid.View as CollectionViewAdv).CurrentAddItem = new OrderInfo(1002, "Ana Trujilo", "Mexico", "ANATR", "Mexico D.F."); 
            this.sfDataGrid.View.CommitNew(); 
        } 
 
        base.HandleKeyOperations(args); 
 
    } 
} 
 
please find sample link below 
  
 
How can I programatically open a form when double-clicking a currently selected row in an SfDataGrid? 
 
You can achieve your requirement to open the form when double click the grid cell by using CellDoubleClick event to customize the popup opening location. 
 
Please find the below code snippet, 
 
sfDataGrid.CellDoubleClick += SfDataGrid_CellDoubleClick; 
 
private void SfDataGrid_CellDoubleClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs e) 
{ 
    var rowData = e.DataRow.RowData as OrderInfo; 
    if (e.DataRow.RowIndex > 0 && rowData != null) 
    { 
        var inlineForm = new InlineForm(); 
        inlineForm.StartPosition = FormStartPosition.Manual; 
        var toolbarHeight = this.Height - this.ClientRectangle.Height; 
        var rowColIndex = sfDataGrid.TableControl.PointToCellRowColumnIndex(e.MouseEventArgs.Location); 
        var cellLocation = sfDataGrid.TableControl.GetCellRectangle(rowColIndex.RowIndex, rowColIndex.ColumnIndex, false).Location; 
        cellLocation.Y = cellLocation.Y + sfDataGrid.RowHeight; 
        inlineForm.Location = sfDataGrid.PointToScreen(cellLocation); 
        inlineForm.ShowDialog(); 
    } 
} 
 
please find sample link below 
  
 
 
 
 
 
Please let us know, if you require further assistance on this. 
  
Regards, 
Gowtham 


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