セルに入力された値によって、セルの移動を禁止させることはできますか?
対象製品
MultiRow for Windows Forms 10.0J
詳細
CellValidatingイベントを使用することで、セルの値を検証することができます。また、CellValidatingイベント内でe.CancelにTrueを設定することでセルの移動を禁止することができます。
[Visual Basic]
[C#]
[Visual Basic]
Imports GrapeCity.Win.MultiRow Private Sub GcMultiRow1_CellValidating(ByVal sender As Object, ByVal e As GrapeCity.Win.MultiRow.CellValidatingEventArgs) Handles GcMultiRow1.CellValidating Select Case e.CellIndex Case 0 ' 第1セルに20よりも大きな値が入力された場合 If e.FormattedValue > 20 Then ' セルの移動を禁止します。 e.Cancel = True End If Case 1 ' 第2セルに文字列が入力されていない場合 If String.IsNullOrEmpty(e.FormattedValue) Then ' セルの移動を禁止します。 e.Cancel = True End If Case 2 ' 第3セルにaが入力された場合 If e.FormattedValue = "a" Then ' セルの移動を禁止します。 e.Cancel = True End If End Select End Sub
[C#]
using GrapeCity.Win.MultiRow; private void gcMultiRow1_CellValidating(object sender, CellValidatingEventArgs e) { switch (e.CellIndex) { case 0: // 第1セルに20よりも大きな値が入力された場合 if (int.Parse(e.FormattedValue.ToString()) > 20) { e.Cancel = true; } break; case 1: // 第2セルに文字列が入力されていない場合 if (e.FormattedValue == null) { // セルの移動を禁止します。 e.Cancel = true; } break; case 2: // 第3セルにaが入力された場合 if ((string)e.FormattedValue == "a") { // セルの移動を禁止します。 e.Cancel = true; } break; } }