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

AddNewRow Shortcut Key

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.




2 Replies

ER ER December 10, 2019 10:42 AM UTC

Hi Syncfusion Team,

No replies yet???




GG Gowtham Gopalsamy Syncfusion Team 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 


Loader.
Live Chat Icon For mobile
Up arrow icon