New to Telerik UI for .NET MAUI? Start a free 30-day trial
Implementing Additional Logic for Shift+Enter Keys in DataGrid on Windows
Updated on Jan 14, 2026
Environment
| Version | Product | Author |
|---|---|---|
| 12.1.0 | Telerik UI for .NET MAUI DataGrid | Dobrinka Yordanova |
Description
I want to implement additional logic for handling Shift+Enter keyboard keys in the DataGrid component on Windows. The RadKeyboardKey enumeration doesn't include the Shift key, and I need a way to determine if the Shift key is pressed.
This knowledge base article also answers the following questions:
- How to detect
Shiftkey press in DataGrid for UI for .NET MAUI? - How to override default key handling in DataGrid on Windows?
- How to execute custom logic for
Shift+Enterkeys in .NET MAUI DataGrid?
Solution
To achieve this, extend the key handling logic in the Execute method of the DataGrid KeyDownCommand. Use the Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread method to detect the Shift key press on Windows. Follow these steps:
- Use the DataGrid
KeyDownCommand. Define a class by inheriting fromDataGridCommand. - Override the
Executemethod to implement logic for handling theShiftkey. - Use the
IsShiftKeyDownmethod to detect if theShiftkey is pressed.
csharp
using System.Collections.ObjectModel;
using System.Reflection;
using Telerik.Maui.Controls;
using Telerik.Maui.Controls.DataGrid;
#if WINDOWS
using Windows.UI.Core;
#endif
public class ShiftEnterDataGridKeydownCommand : DataGridCommand
{
public ShiftEnterDataGridKeydownCommand()
{
Id = DataGridCommandId.KeyDown;
}
public override bool CanExecute(object parameter)
{
return true;
}
public override void Execute(object parameter)
{
if (parameter is KeyboardInfo keyboardInfo)
{
if (keyboardInfo.key == Telerik.Maui.RadKeyboardKey.Down)
{
var newKey = new KeyboardInfo(Telerik.Maui.RadKeyboardKey.Enter, () => { });
this.Owner.CommandService.ExecuteDefaultCommand(Id, newKey);
}
else if (keyboardInfo.key == Telerik.Maui.RadKeyboardKey.Enter)
{
if (IsShiftKeyDown())
{
// add your logic here
return;
}
}
else
{
this.Owner.CommandService.ExecuteDefaultCommand(Id, parameter);
}
}
}
internal static bool IsShiftKeyDown(VisualElement visualElement = null)
{
#if WINDOWS
CoreVirtualKeyStates controlStates = Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(global::Windows.System.VirtualKey.Shift);
bool isShiftKeyDown = controlStates.HasFlag(CoreVirtualKeyStates.Down);
return isShiftKeyDown;
#else
return false;
#endif
}
}