CellValidating イベントで任意のセルに移動する方法
対象製品
MultiRow for Windows Forms 5.0J
詳細
GcMultiRow.CellValidating イベントで現在のセルの位置を変更すると、そのセル移動によって新たにイベントが発生するため、位置の変更が繰り替えされる無限ループになってしまいます。このとき、最終的に StackOverFlowException の例外で処理が中断します。
この現象を回避するには、コーディングでセルを移動する際に、この処理をユーザーの操作と区別するようにコーディングします。
[Visual Basic]
[C#]
この現象を回避するには、コーディングでセルを移動する際に、この処理をユーザーの操作と区別するようにコーディングします。
[Visual Basic]
Imports GrapeCity.Win.MultiRow
Private IsControled As Boolean = False
Private Sub GcMultiRow1_CellValidating(ByVal sender As System.Object, ByVal e As CellValidatingEventArgs) Handles GcMultiRow1.CellValidating
// 現在のセルがインデックス 0 のとき、インデックス 3 に移動します。
If IsControled Then
IsControled = False
ElseIf e.CellIndex = 0 Then
e.Cancel = True
IsControled = True
GcMultiRow1.CurrentCellPosition = New CellPosition(e.RowIndex, 3)
End If
End Sub
Private IsControled As Boolean = False
Private Sub GcMultiRow1_CellValidating(ByVal sender As System.Object, ByVal e As CellValidatingEventArgs) Handles GcMultiRow1.CellValidating
// 現在のセルがインデックス 0 のとき、インデックス 3 に移動します。
If IsControled Then
IsControled = False
ElseIf e.CellIndex = 0 Then
e.Cancel = True
IsControled = True
GcMultiRow1.CurrentCellPosition = New CellPosition(e.RowIndex, 3)
End If
End Sub
[C#]
using GrapeCity.Win.MultiRow;
private bool isControled = false;
private void gcMultiRow1_CellValidating(object sender, CellValidatingEventArgs e)
{
// 現在のセルがインデックス 0 のとき、インデックス 3 に移動します。
if (isControled)
{
isControled = false;
}
else if (e.CellIndex == 0)
{
e.Cancel = true;
isControled = true;
gcMultiRow1.CurrentCellPosition = new CellPosition(e.RowIndex, 3);
}
}
private bool isControled = false;
private void gcMultiRow1_CellValidating(object sender, CellValidatingEventArgs e)
{
// 現在のセルがインデックス 0 のとき、インデックス 3 に移動します。
if (isControled)
{
isControled = false;
}
else if (e.CellIndex == 0)
{
e.Cancel = true;
isControled = true;
gcMultiRow1.CurrentCellPosition = new CellPosition(e.RowIndex, 3);
}
}
この文書は、以前は次のFAQ IDで公開されていました : 11446