InputManCellでドロップダウンを表示するショートカットキーF4を無効にするには?
対象製品
MultiRow for Windows Forms 7.0J
詳細
コンボボックス型セルやGcComboBoxCellなど一部のセル型では、デフォルトで編集状態のときにF4キーを押下するとドロップダウンを表示する動作になっています。このショートカットキー動作は、MultiRowコントロールのShortcutKeyManagerで変更することはできません。この動作を無効にするには、フォームのKeyPreviewプロパティをTrueに設定して、フォームのKeyDownイベントでキー操作をキャンセルすることで実現することができます。
[Visual Basic]
Imports GrapeCity.Win.MultiRow
Imports GrapeCity.Win.MultiRow.InputMan
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' セル型の作成
Dim textCell As New GcTextBoxCell()
textCell.Name = "textCell"
Dim comboCell As New GcComboBoxCell()
comboCell.Name = "comboCell"
comboCell.Items.AddRange(New String() {"A", "B", "C"})
Dim numberCell As New GcNumberCell()
numberCell.Name = "numberCell"
' MultiRowの設定
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {textCell, comboCell, numberCell})
GcMultiRow1.RowCount = 5
' MultiRowが非編集状態のときのF4キーによるドロップダウン動作の禁止
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.F4)
' FormでのKeyDownイベントの先行検出
Me.KeyPreview = True
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
' MultiRowが編集状態のときのF4キーによるドロップダウン動作の禁止
If e.KeyCode = Keys.F4 Then
If GcMultiRow1.ContainsFocus Then
e.SuppressKeyPress = True
End If
End If
End Sub
End Class
[C#]
using GrapeCity.Win.MultiRow;
using GrapeCity.Win.MultiRow.InputMan;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// セル型の作成
GcTextBoxCell textCell = new GcTextBoxCell();
textCell.Name = "textCell";
GcComboBoxCell comboCell = new GcComboBoxCell();
comboCell.Name = "comboCell";
comboCell.Items.AddRange(new string[] { "A", "B", "C" });
GcNumberCell numberCell = new GcNumberCell();
numberCell.Name = "numberCell";
// テンプレートの作成
Template template1 = Template.CreateGridTemplate(new Cell[] { textCell, comboCell, numberCell });
// MultiRowの設定
gcMultiRow1.Template = template1;
gcMultiRow1.RowCount = 5;
// MultiRowに割り当てられたF4キーのショートカット機能の解除
gcMultiRow1.ShortcutKeyManager.Unregister(Keys.F4);
this.KeyPreview = true;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
// MultiRowが編集状態のときのF4キーによるドロップダウン動作の禁止
if (e.KeyCode == Keys.F4)
{
if (gcMultiRow1.ContainsFocus)
{
e.SuppressKeyPress = true;
}
}
}
}
}
[Visual Basic]
Imports GrapeCity.Win.MultiRow
Imports GrapeCity.Win.MultiRow.InputMan
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' セル型の作成
Dim textCell As New GcTextBoxCell()
textCell.Name = "textCell"
Dim comboCell As New GcComboBoxCell()
comboCell.Name = "comboCell"
comboCell.Items.AddRange(New String() {"A", "B", "C"})
Dim numberCell As New GcNumberCell()
numberCell.Name = "numberCell"
' MultiRowの設定
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {textCell, comboCell, numberCell})
GcMultiRow1.RowCount = 5
' MultiRowが非編集状態のときのF4キーによるドロップダウン動作の禁止
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.F4)
' FormでのKeyDownイベントの先行検出
Me.KeyPreview = True
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
' MultiRowが編集状態のときのF4キーによるドロップダウン動作の禁止
If e.KeyCode = Keys.F4 Then
If GcMultiRow1.ContainsFocus Then
e.SuppressKeyPress = True
End If
End If
End Sub
End Class
[C#]
using GrapeCity.Win.MultiRow;
using GrapeCity.Win.MultiRow.InputMan;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// セル型の作成
GcTextBoxCell textCell = new GcTextBoxCell();
textCell.Name = "textCell";
GcComboBoxCell comboCell = new GcComboBoxCell();
comboCell.Name = "comboCell";
comboCell.Items.AddRange(new string[] { "A", "B", "C" });
GcNumberCell numberCell = new GcNumberCell();
numberCell.Name = "numberCell";
// テンプレートの作成
Template template1 = Template.CreateGridTemplate(new Cell[] { textCell, comboCell, numberCell });
// MultiRowの設定
gcMultiRow1.Template = template1;
gcMultiRow1.RowCount = 5;
// MultiRowに割り当てられたF4キーのショートカット機能の解除
gcMultiRow1.ShortcutKeyManager.Unregister(Keys.F4);
this.KeyPreview = true;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
// MultiRowが編集状態のときのF4キーによるドロップダウン動作の禁止
if (e.KeyCode == Keys.F4)
{
if (gcMultiRow1.ContainsFocus)
{
e.SuppressKeyPress = true;
}
}
}
}
}