行選択モードの場合にEl Tabelle MultiRow 4.0Jのように矢印キーでセル単位の移動はできますか?
対象製品
MultiRow for Windows Forms 7.0J
詳細
行選択モードの場合、既定では矢印キーは行単位で移動する動作になります。セル単位で移動するにはショートカットキーの定義を変更する必要があります。
また、現在のセルの背景色が行の背景色と同じになっているため、見えづらい場合があります。現在のセルのスタイルを変更するには、ダイナミックスタイルを設定する方法が考えられます。
下記のサンプルコードは、行選択モードで矢印キーの動作を変更する方法と現在のセルのスタイルを変更する方法を示しています。
[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
' カレントセルの選択色を切り替えるためのダイナミックセルスタイルの作成
Dim style1 As New DynamicCellStyle
style1.ConditionHandler = New DynamicCellStyleConditionHandler(AddressOf CustomCondition)
' セル型の作成
Dim textCell1 As New TextBoxCell()
textCell1.Name = "textCell1"
textCell1.Style = style1
textCell1.Size = New Size(textCell1.Width, 40)
Dim textCell2 As New TextBoxCell()
textCell2.Name = "textCell2"
textCell2.Style = style1
textCell2.Size = New Size(textCell2.Width, 40)
' MultiRowの設定
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {textCell1, textCell2})
GcMultiRow1.RowCount = 5
GcMultiRow1.ViewMode = ViewMode.Row
' 矢印キーの動作の変更
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Left)
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Right)
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Up)
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Down)
GcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveLeft, Keys.Left)
GcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveRight, Keys.Right)
GcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveUp, Keys.Up)
GcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveDown, Keys.Down)
End Sub
Private Function CustomCondition(ByVal context As DynamicCellStyleContext) As CellStyle
' 既定のスタイルの設定
Dim cStyle As New CellStyle()
cStyle.Multiline = MultiRowTriState.[True]
' カレントセルの場合のスタイル設定
If context.CellScope = CellScope.Row Then
If context.RowIndex = context.GcMultiRow.CurrentCellPosition.RowIndex AndAlso context.CellIndex = context.GcMultiRow.CurrentCellPosition.CellIndex Then
' カレントセルの選択色を変更します。
cStyle.SelectionBackColor = SystemColors.Window
cStyle.SelectionForeColor = SystemColors.WindowText
End If
End If
' 戻り値の設定
Return cStyle
End Function
End Class
[C#]
using GrapeCity.Win.MultiRow;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// カレントセルの選択色を切り替えるためのダイナミックセルスタイルの作成
DynamicCellStyle style1 = new DynamicCellStyle(CustomCondition);
// セル型の作成
TextBoxCell textCell1 = new TextBoxCell();
textCell1.Name = "textCell1";
textCell1.Style = style1;
textCell1.Size = new Size(textCell1.Width, 40);
TextBoxCell textCell2 = new TextBoxCell();
textCell2.Name = "textCell2";
textCell2.Style = style1;
textCell2.Size = new Size(textCell2.Width, 40);
// MultiRowの設定
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { textCell1, textCell2 });
gcMultiRow1.RowCount = 5;
gcMultiRow1.ViewMode = ViewMode.Row;
// 左右矢印キーの動作の変更
gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Left);
gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Right);
gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Up);
gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Down);
gcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveLeft, Keys.Left);
gcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveRight, Keys.Right);
gcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveUp, Keys.Up);
gcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveDown, Keys.Down);
}
private CellStyle CustomCondition(DynamicCellStyleContext context)
{
// 既定のスタイルの設定
CellStyle cStyle = new CellStyle();
cStyle.Multiline = MultiRowTriState.True;
// カレントセルの場合のスタイル設定
if (context.CellScope == CellScope.Row)
{
if (context.RowIndex == context.GcMultiRow.CurrentCellPosition.RowIndex && context.CellIndex == context.GcMultiRow.CurrentCellPosition.CellIndex)
{
// カレントセルの選択色を変更します。
cStyle.SelectionBackColor = SystemColors.Window;
cStyle.SelectionForeColor = SystemColors.WindowText;
}
}
// 戻り値の設定
return cStyle;
}
}
}
また、現在のセルの背景色が行の背景色と同じになっているため、見えづらい場合があります。現在のセルのスタイルを変更するには、ダイナミックスタイルを設定する方法が考えられます。
下記のサンプルコードは、行選択モードで矢印キーの動作を変更する方法と現在のセルのスタイルを変更する方法を示しています。
[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
' カレントセルの選択色を切り替えるためのダイナミックセルスタイルの作成
Dim style1 As New DynamicCellStyle
style1.ConditionHandler = New DynamicCellStyleConditionHandler(AddressOf CustomCondition)
' セル型の作成
Dim textCell1 As New TextBoxCell()
textCell1.Name = "textCell1"
textCell1.Style = style1
textCell1.Size = New Size(textCell1.Width, 40)
Dim textCell2 As New TextBoxCell()
textCell2.Name = "textCell2"
textCell2.Style = style1
textCell2.Size = New Size(textCell2.Width, 40)
' MultiRowの設定
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {textCell1, textCell2})
GcMultiRow1.RowCount = 5
GcMultiRow1.ViewMode = ViewMode.Row
' 矢印キーの動作の変更
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Left)
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Right)
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Up)
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Down)
GcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveLeft, Keys.Left)
GcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveRight, Keys.Right)
GcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveUp, Keys.Up)
GcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveDown, Keys.Down)
End Sub
Private Function CustomCondition(ByVal context As DynamicCellStyleContext) As CellStyle
' 既定のスタイルの設定
Dim cStyle As New CellStyle()
cStyle.Multiline = MultiRowTriState.[True]
' カレントセルの場合のスタイル設定
If context.CellScope = CellScope.Row Then
If context.RowIndex = context.GcMultiRow.CurrentCellPosition.RowIndex AndAlso context.CellIndex = context.GcMultiRow.CurrentCellPosition.CellIndex Then
' カレントセルの選択色を変更します。
cStyle.SelectionBackColor = SystemColors.Window
cStyle.SelectionForeColor = SystemColors.WindowText
End If
End If
' 戻り値の設定
Return cStyle
End Function
End Class
[C#]
using GrapeCity.Win.MultiRow;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// カレントセルの選択色を切り替えるためのダイナミックセルスタイルの作成
DynamicCellStyle style1 = new DynamicCellStyle(CustomCondition);
// セル型の作成
TextBoxCell textCell1 = new TextBoxCell();
textCell1.Name = "textCell1";
textCell1.Style = style1;
textCell1.Size = new Size(textCell1.Width, 40);
TextBoxCell textCell2 = new TextBoxCell();
textCell2.Name = "textCell2";
textCell2.Style = style1;
textCell2.Size = new Size(textCell2.Width, 40);
// MultiRowの設定
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { textCell1, textCell2 });
gcMultiRow1.RowCount = 5;
gcMultiRow1.ViewMode = ViewMode.Row;
// 左右矢印キーの動作の変更
gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Left);
gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Right);
gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Up);
gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Down);
gcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveLeft, Keys.Left);
gcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveRight, Keys.Right);
gcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveUp, Keys.Up);
gcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveDown, Keys.Down);
}
private CellStyle CustomCondition(DynamicCellStyleContext context)
{
// 既定のスタイルの設定
CellStyle cStyle = new CellStyle();
cStyle.Multiline = MultiRowTriState.True;
// カレントセルの場合のスタイル設定
if (context.CellScope == CellScope.Row)
{
if (context.RowIndex == context.GcMultiRow.CurrentCellPosition.RowIndex && context.CellIndex == context.GcMultiRow.CurrentCellPosition.CellIndex)
{
// カレントセルの選択色を変更します。
cStyle.SelectionBackColor = SystemColors.Window;
cStyle.SelectionForeColor = SystemColors.WindowText;
}
}
// 戻り値の設定
return cStyle;
}
}
}