作成日: 2022/03/11 最終更新日: 2022/03/30
文書種別
使用方法
詳細
FormのKeyDownイベントでキー操作をキャンセルして上下矢印キーの動作を制限することで、左右矢印キーのみでの選択に変更することが可能です。
[Visual Basic]
C#
[Visual Basic]
Imports GrapeCity.Win.MultiRow
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' セル型の作成
Dim radioCell As New RadioGroupCell()
radioCell.Name = "radioCell"
radioCell.Size = New Size(100, radioCell.Height)
radioCell.Items.AddRange(New String() {"A", "B", "C"})
radioCell.FlowDirection = Orientation.Horizontal
radioCell.ColumnCount = 3
Dim textCell As New TextBoxCell()
textCell.Name = "textCell"
' MultiRowの設定
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {radioCell, textCell})
GcMultiRow1.RowCount = 5
' Formの設定
Me.KeyPreview = True
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
' 上下矢印キーによる選択項目の移動を禁止します。
If e.KeyCode = Keys.Up OrElse e.KeyCode = Keys.Down Then
Dim isRadio As Boolean = (TypeOf Me.ActiveControl Is GcMultiRow) And (TypeOf GcMultiRow1.CurrentCell Is RadioGroupCell)
If isRadio Then
e.Handled = True
End If
End If
End Sub
End Class
C#
using GrapeCity.Win.MultiRow;
namespace sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.KeyDown += Form1_KeyDown;
}
private void Form1_Load(object sender, EventArgs e)
{
// セル型の作成
RadioGroupCell radioCell = new RadioGroupCell();
radioCell.Name = "radioCell";
radioCell.Size = new Size(100, radioCell.Height);
radioCell.Items.AddRange(new string[] { "A", "B", "C" });
radioCell.FlowDirection = Orientation.Horizontal;
radioCell.ColumnCount = 3;
TextBoxCell textCell = new TextBoxCell();
textCell.Name = "textCell";
// MultiRowの設定
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { radioCell, textCell });
gcMultiRow1.RowCount = 5;
// Formの設定
this.KeyPreview = true;
}
private void Form1_KeyDown(object Object, KeyEventArgs e)
{
// 上下矢印キーによる選択項目の移動を禁止します。
if ((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Down))
{
bool isRadio = ((GcMultiRow)this.ActiveControl is GcMultiRow) && ((RadioGroupCell)gcMultiRow1.CurrentCell is RadioGroupCell);
if (isRadio)
{
e.Handled = true;
}
}
}
}
}