Prevent Grid from Processing Return Key
Please find the responses for the reported queries.
|
Query |
Comments | |
|
I'm using SfDataGrid to display data and have disabled Editing & Deleting. I'm handling Enter & Deleted KeyUp event from vb.net code to perform stuffs If user presses Enter Key, Selected Row Changes i.e. focus gets to next row and it gets selected. How can I prevent this? |
You can handle Enter key behavior by overriding ProcessKeyDown method in GridSelectionController classs.
You can refer the below KB for more information. https://www.syncfusion.com/kb/3815/how-to-change-the-enter-key-behavior-in-sfdatagrid | |
|
Also when user double clicks on particular row I want to raise KeyUp Event with enter key. How Can I achieve this also. |
It is not possible to raise key up event when double clicking. But you can override double click in selection controller and do needed action. |
Regards,
Gnanasownthari T
Your code is correct. Can you please let us know the problem you are facing with this code.
You can override GridSelectionContoller also to handler double click as like in the below code snippet also.
|
this.dataGrid.SelectionController = new GridSelectionControllerExt(dataGrid);
public class GridSelectionControllerExt : GridSelectionController { public GridSelectionControllerExt(SfDataGrid dataGrid) : base(dataGrid) {
} public override void HandlePointerOperations(GridPointerEventArgs args, RowColumnIndex rowColumnIndex) { if (args.Operation == PointerOperation.DoubleTapped) this.HandleKeyDown(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(this.DataGrid), 0, Key.Enter));
else base.HandlePointerOperations(args, rowColumnIndex); } |
Can you please let us know the problem you are facing. That will help us to provide better solution.
Thanks,
Sivakumar
Thanks for the code snippet shared in the previous update. Please find the modified code snippet to achieve your requirement. Now OnKeyUp is triggered in when double clicking mouse as expected.
Sample:
http://www.syncfusion.com/downloads/support/forum/123198/ze/GridSelectionController-2072735055
Code snippet:
|
public class GSLV : SfDataGrid { protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); }
protected override void OnKeyUp(KeyEventArgs e) { Console.WriteLine("Enter triggered"); base.OnKeyUp(e); }
protected override void OnMouseDoubleClick(MouseButtonEventArgs e) { this.OnKeyUp(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(this), 0, Key.Enter)); //base.OnMouseDoubleClick(e); } }
public class GridSelectionControllerExt : GridSelectionController { public GridSelectionControllerExt(SfDataGrid dataGrid) : base(dataGrid) {
}
public override bool HandleKeyDown(KeyEventArgs args) { if (args.Key == Key.Enter) return false; return base.HandleKeyDown(args); }
public override void HandlePointerOperations(GridPointerEventArgs args, RowColumnIndex rowColumnIndex) { if (args.Operation == PointerOperation.DoubleTapped) return; else base.HandlePointerOperations(args, rowColumnIndex); } |
Thanks,
Sivakumar
We are glad that your issue has been fixed.
Please let us know if you need any other assistance.
Regards,
Ashwini P.
- 8 Replies
- 4 Participants
-
AS Amit Saraf
- Feb 25, 2016 10:19 AM UTC
- Mar 3, 2016 12:13 PM UTC