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

Keybord Editing

I uploaded module description in the Attach file.
Our user have some keyboard input needs like below:
step 1.When i click add button,the sfdatagrid add a new row.
step 2.The first column-the comboboxcolumn is in editing mode and the dropdown is open.
step 3.After selecttion ,When press "Enter"(User want to replace Tab with Enter),move to the third column-"Title" ,and this column is in edit mode.
step 4.When user edit the last column and press Enter,It will create a new row and move to step 2.  

Input is pure keyboard action,how to do it with sfdatagrid

Attachment: QQ截图20160330145435_1070f754.7z

5 Replies

JS Jayapradha S Syncfusion Team March 31, 2016 01:07 PM UTC

Hi Ray,

Thank you for contacting Syncfusion Support.

We have analyzed your requirement that while pressing tab or enter key specific cell gets enter into edit mode  and you can achieve this by overriding the GridSelectionController and override the ProcessKeyDown method to change the enter and tab key behavior as you expected.

Code Example:

public class GridSelectionControllerExt:GridSelectionController

{

SfDataGrid sfGrid;

public GridSelectionControllerExt(SfDataGrid dataGrid):base(dataGrid)

{

sfGrid = dataGrid;

}

protected override void ProcessKeyDown(KeyEventArgs args)

{

var rowIndex = this.sfGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex;

var colIndex = this.sfGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.ColumnIndex;

if(args.Key==Key.Enter || args.Key== Key.Tab)

{

if (colIndex == 0)

{

this.sfGrid.SelectionController.MoveCurrentCell(new RowColumnIndex(rowIndex, 2));

App.Current.Dispatcher.BeginInvoke(new Action(() =>

{

    this.sfGrid.SelectionController.CurrentCellManager.BeginEdit();


}), DispatcherPriority.ApplicationIdle);    

args.Handled = true;

}

}

base.ProcessKeyDown(args);

}
}


We have prepared a sample for your requirement and please find the sample from the following location,
Sample Link: http://www.syncfusion.com/downloads/support/forum/123552/ze/WPF-810080025


Regarding step1 and step 4:
In Step 1, do you want to add an empty record to grid or do you enable the AddNewRow feature in Button Click.
In Step 4, you have mentioned while pressing Enter/Tab key, create a new row and move to step2. Here, do you want to create a new row by using AddNewRow feature?

Please share your requirement in detail.


If you want to create a new row by using AddNewNow and you can handle the enter/tab keys in AddNewRow as explained in the below KB document,

KB Link: https://www.syncfusion.com/kb/4736/how-to-move-the-currentcell-to-the-first-column-of-the-addnewrow-when-the-tab-key-is-pressed-from-the


Regards,
Jayapradha



RA ray April 1, 2016 02:11 AM UTC

Thanks a lot.It's really a great help. Step 4 --After i  edited the last column-"Title", press the "Enter",I  want to add a new row just like click the AddNewButton.So it's a pure keyboard action.Sorry for my poor english.


JS Jayapradha S Syncfusion Team April 1, 2016 01:18 PM UTC

Hi Ray,

Thank you for your update.

You can add a new row when pressing a Enter/Tab key in last column “Title” by overriding the ProcessKeyDown method in Overridden GridSelectionController class. Please find the modified sample which including the step 4.

protected override void ProcessKeyDown(KeyEventArgs args)

{

    var rowIndex = this.sfGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex;

    var colIndex = this.sfGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.ColumnIndex;

    if(args.Key==Key.Enter || args.Key== Key.Tab && !this.sfGrid.IsAddNewIndex(rowIndex))

    {

        if (colIndex == 0)

        {

            this.sfGrid.SelectionController.MoveCurrentCell(new RowColumnIndex(rowIndex, 2));

            App.Current.Dispatcher.BeginInvoke(new Action(() =>

            {

                this.sfGrid.SelectionController.CurrentCellManager.BeginEdit();


            }), DispatcherPriority.ApplicationIdle);

            args.Handled = true;

        }

        if(colIndex==2)

        {

            var viewModel = this.sfGrid.DataContext as ViewModel;

            var record = new StoreList("Magazine", true, "Johnson");

            viewModel.CategoryCombo.Add("Magazine");

            viewModel.StoreLists.Add(record);

            colIndex = 0;

            rowIndex = this.sfGrid.ResolveToRowIndex(record);

            this.sfGrid.SelectionController.MoveCurrentCell(new RowColumnIndex(rowIndex,colIndex));


           App.Current.Dispatcher.BeginInvoke(new Action(() =>

            {

                this.sfGrid.SelectionController.CurrentCellManager.BeginEdit();

            }), DispatcherPriority.ApplicationIdle);

           args.Handled=true;

            return;

        }

    }

   

     base.ProcessKeyDown(args);
}


Step 4 => while pressing a Enter/Tab key in “Title” column then current cell will be moved to ComboBox Column and dropdown will be opened and again when pressed a Enter/Tab key allows you to change the current cell as “Title” column with Edit mode by invoking SfDataGrid.SelectionController.CurrentCellManager.BeginEdit().


Sample Link: http://www.syncfusion.com/downloads/support/forum/123552/ze/WPF_AddNewRow_EnterKey583511457.zip

Regards,
Jayapradha


RA ray April 1, 2016 02:25 PM UTC

Thanks a lot.Works Great.


AP Ashwini Paranthaman Syncfusion Team April 4, 2016 07:02 AM UTC

Hi Ray,
We are glad that your issue has been fixed.
Please let us know if you need any other assistance.
Regards,
Ashwini P.

Loader.
Up arrow icon