フォーカスを最終セルから次のコントロールに移動させたい
対象製品
MultiRow for Windows Forms 8.0J
詳細
以下のSelectionActionsをショートカットキーに割り当てることで、別のコントロールにフォーカスを移動することができます。
[C#]
また、ComponentActions.SelectNextControlプロパティを実行すると、TabIndexに従ってフォーカスをフォーム内の次のコントロールに移動します。現在のセルが最終行の最終セルかどうかを判定してフォーカスを移動するようにユーザー定義のショートカットキーを割り当てることで実現することができます。
[Visual Basic]
[C#]
- SelectionActions.MoveToNextCellThenControl
- SelectionActions.MoveToPreviousCellThenControl
' Tabキー、Shiftキー+Tabキーの既定のショートカットキーを解除する。 GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Tab) GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Shift Or Keys.Tab) ' TabキーのショートカットキーにMoveToNextCellThenControlを割り当てる。 GcMultiRow1.ShortcutKeyManager.Register(GrapeCity.Win.MultiRow.SelectionActions.MoveToNextCellThenControl, Keys.Tab) ' Shiftキー+TabキーのショートカットキーにMoveToPreviousCellThenControlを割り当てる。 GcMultiRow1.ShortcutKeyManager.Register(GrapeCity.Win.MultiRow.SelectionActions.MoveToPreviousCellThenControl, Keys.Shift Or Keys.Tab)
[C#]
// Tabキー、Shiftキー+Tabキーの既定のショートカットキーを解除する。 gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Tab); gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Shift | Keys.Tab); // TabキーのショートカットキーにMoveToNextCellThenControlを割り当てる。 gcMultiRow1.ShortcutKeyManager.Register(GrapeCity.Win.MultiRow.SelectionActions.MoveToNextCellThenControl, Keys.Tab); // Shiftキー+TabキーのショートカットキーにMoveToPreviousCellThenControlを割り当てる。 gcMultiRow1.ShortcutKeyManager.Register(GrapeCity.Win.MultiRow.SelectionActions.MoveToPreviousCellThenControl, Keys.Shift | Keys.Tab);
また、ComponentActions.SelectNextControlプロパティを実行すると、TabIndexに従ってフォーカスをフォーム内の次のコントロールに移動します。現在のセルが最終行の最終セルかどうかを判定してフォーカスを移動するようにユーザー定義のショートカットキーを割り当てることで実現することができます。
[Visual Basic]
Imports GrapeCity.Win.MultiRow Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Tabキーの既定のショートカットキーを解除する。 GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Tab) ' Tabキーのショートカットキーにユーザー定義のショートカットキーを割り当てる。 GcMultiRow1.ShortcutKeyManager.Register(New CustomMoveToNextControl(), Keys.Tab) End Sub End Class Public Class CustomMoveToNextControl Implements IAction Public Function CanExecute(ByVal target As GcMultiRow) As Boolean Implements IAction.CanExecute Return True End Function Public ReadOnly Property DisplayName() As String Implements IAction.DisplayName Get Return Me.ToString() End Get End Property Public Sub Execute(ByVal target As GcMultiRow) Implements IAction.Execute Dim isLastRow As Boolean = (target.CurrentCellPosition.RowIndex = target.RowCount - 1) Dim isLastCell As Boolean = (target.CurrentCellPosition.CellIndex = target.Rows(0).Cells.Count - 2) If Not (isLastRow And isLastCell) Then ' 最後のセル以外のセルでは次のセルへ移動します。 SelectionActions.MoveToNextCell.Execute(target) Else ' 最後のセルでは次のコントロールへ移動します。 ComponentActions.SelectNextControl.Execute(target) End If End Sub End Class
[C#]
using System; using System.Windows.Forms; using GrapeCity.Win.MultiRow; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Tabキーの既定のショートカットキーを解除する。 gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Tab); // Tabキーのショートカットキーにユーザー定義のショートカットキーを割り当てる。 gcMultiRow1.ShortcutKeyManager.Register(new CustomMoveToNextControl(), Keys.Tab); } } public class CustomMoveToNextControl : IAction { public bool CanExecute(GcMultiRow target) { return true; } public string DisplayName { get { return this.ToString(); } } public void Execute(GcMultiRow target) { Boolean isLastRow = (target.CurrentCellPosition.RowIndex == target.RowCount - 1); Boolean isLastCell = (target.CurrentCellPosition.CellIndex == target.Template.Row.Cells.Count - 2); if (!(isLastRow & isLastCell)) { // 最後のセル以外のセルでは次のセルへ移動します。 SelectionActions.MoveToNextCell.Execute(target); } else { // 最後のセルでは次のコントロールへ移動します。 ComponentActions.SelectNextControl.Execute(target); } } } }