作成日: 2026/06/24 最終更新日: 2026/06/24
文書種別
使用方法
詳細
GcSpreadGridの[Tab]キーの動作は、MoveNextコマンドに関連付けられています。このため、既定では、[Tab]キーを押下すると次のセルに移動します。
この動作を変更して、[Tab]キーで次のコントロールに移動するには、.NET Frameworkで提供されているInputBindingsプロパティを使用します。
以下のサンプルコードでは、[Tab]キーの既定のコマンドを無効にしています。これにより、WPFコントロールの既定の動作が適用され、[Tab]キーで次のコントロールに移動するようになります。
◎サンプルコード(XAML)
<sg:GcSpreadGrid x:Name="GcSpreadGrid1">
<sg:GcSpreadGrid.InputBindings>
<KeyBinding Key="Tab" Command="ApplicationCommands.NotACommand" />
</sg:GcSpreadGrid.InputBindings>
</sg:GcSpreadGrid>
また、同様に、[Shift] + [Tab]キーで前のコントロールに戻る場合も、InputBindingsプロパティを使用します。ただし、こちらは既定のコマンドを無効にするだけでは正しく動作しません。このため、以下のサンプルコードのように、MovefocusPreviousCommandコマンドを作成し、このコマンドを[Shift] + [Tab]キーに割り当てます。
◎サンプルコード(XAML)
<sg:GcSpreadGrid x:Name="GcSpreadGrid1">
<sg:GcSpreadGrid.Resources>
<local:MovefocusPreviousCommand x:Key="cmd1" />
</sg:GcSpreadGrid.Resources>
<sg:GcSpreadGrid.InputBindings>
<KeyBinding Key="Tab" Modifiers="Shift" Command="{StaticResource cmd1}" />
</sg:GcSpreadGrid.InputBindings>
</sg:GcSpreadGrid>
◎サンプルコード(C#)
public class MovefocusPreviousCommand : ICommand
{
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
FrameworkElement element = Keyboard.PrimaryDevice.FocusedElement as FrameworkElement;
if (element != null)
{
DependencyObject parent = element;
while (parent != null && !(parent is GcSpreadGrid))
{
parent = VisualTreeHelper.GetParent(parent);
}
if (parent != null)
{
(parent as GcSpreadGrid).MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
}
}
}
}
なお、ショートカットキーについては、製品ヘルプの以下のトピックをご参照ください。
[SPREAD for WPF 5.0J - GcSpreadGrid]
- [開発者ガイド]
- [キーボード操作]
関連情報