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. |
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); } |
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); } |