Keybord Editing
Attachment: QQ截图20160330145435_1070f754.7z
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
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
We are glad that your issue has been fixed.
Please let us know if you need any other assistance.
Regards,
Ashwini P.
- 5 Replies
- 3 Participants
-
RA ray
- Mar 30, 2016 08:12 AM UTC
- Apr 4, 2016 07:02 AM UTC