Row Shortcut KeyBindings

How to add keybindings for sfdatagrid?

Eg: F2 key for performing an action for grid rows. On selecting a  row and pressing F2 I need to implement my own function. 

3 Replies

JG Jai Ganesh S Syncfusion Team November 15, 2017 09:57 AM UTC

 
You can implement your own function when pressing F2 key after selecting the row by customize the GridSelectionController and override the ProcessKeyDown method like below, 
 
this.datagrid.SelectionController = new CustomSelectionController(this.datagrid); 
public class CustomSelectionController : GridSelectionController 
{ 
    public CustomSelectionController(SfDataGrid dataGrid) 
        : base(dataGrid) 
    { 
    } 
 
    protected override void ProcessKeyDown(KeyEventArgs args) 
    { 
        // Get the CurrentCell column index  
        var currentColumnIndex = this.CurrentCellManager.CurrentRowColumnIndex.ColumnIndex; 
 
        base.ProcessKeyDown(args); 
 
        if (SelectionHelper.CheckShiftKeyPressed()) 
            return; 
        if (args.Key == Key.F2) 
        { 
            //Do your actions here 
        } 
    } 
} 
 
 
Regards, 
Jai Ganesh S


BR brijesh November 15, 2017 10:24 AM UTC

Hi Jai,

Your solution worked like a charm for single key. Thank you so much. But I also have a requirement of modifiers.

Eg. Alt + Ctrl + A, Ctrl + B, Alt + B

How can I achieve this?


JG Jai Ganesh S Syncfusion Team November 16, 2017 12:27 PM UTC

 
We have modified our sample to achieve your requirement for accessing the Alt + Ctrl + A, Ctrl + B keys in ProcessKeyDown method, 
 
protected override void ProcessKeyDown(KeyEventArgs args) 
{ 
    // Get the CurrentCell column index  
    var currentColumnIndex = this.CurrentCellManager.CurrentRowColumnIndex.ColumnIndex; 
 
    base.ProcessKeyDown(args); 
             
    if (SelectionHelper.CheckShiftKeyPressed()) 
        return; 
    if ((SelectionHelper.CheckControlKeyPressed()&& args.Key == Key.B) || 
 
        (SelectionHelper.CheckAltKeyPressed() && SelectionHelper.CheckControlKeyPressed() && args.Key == Key.A) ||  (args.Key == Key.F2)) 
    { 
        //Do your actions here 
    } 
} 
 
 
You cannot use the Alt + B combination because if you are pressing the Alt key then the other menu item in the application getting focused. Could you please refer the below MSDN forums that describes the Alt key functionalities, 
 
 
 
Could you please use the other key combinations along with Alt key like Alt + Ctrl + A in your application instead of using only the Alt key. 
 
Regards, 
Jai Ganesh S

Loader.
Up arrow icon