ユーザーによってセルに入力された値にエラーがある場合、セルまたはセルが属する行にエラーアイコンを表示できます。ユーザーは、マウスカーソルをエラーアイコンにあわせることでエラーの詳細を確認できます。

エラーメッセージの表示方法は「
エラーメッセージの表示」を参照してください。
ユーザーの入力内容にエラーがある場合、検証エラーの内容をバルーンチップで通知し、適切な値への編集を促すことができます。この方法は、常時入力モード(GcMultiRow.EditType=EditType.AlwaysEdit)を使用している場合など、エラーアイコンやエラーチップを表示できない場合に適しています。

次のコードは、最初の文字列型セルに5文字以上が入力されたとき、バルーンチップで検証エラーを通知し、ユーザーに再入力を促します。サンプルコードを実行するためには、あらかじめフォームにToolTipコンポーネント(ToolTip1)を追加する必要があります。
Imports GrapeCity.Win.MultiRow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Enter)
GcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveToNextCell, Keys.Enter)
End Sub
Private Sub GcMultiRow1_CellValidating(ByVal sender As System.Object, ByVal e As GrapeCity.Win.MultiRow.CellValidatingEventArgs) Handles GcMultiRow1.CellValidating
Dim gcMultiRow As GcMultiRow = DirectCast(sender, GcMultiRow)
If (e.CellIndex = 0) AndAlso (e.RowIndex = 0) Then
Dim currentCellRect As Rectangle = gcMultiRow.GetCellDisplayRectangle(e.RowIndex, e.CellIndex)
Dim value As String = TryCast(e.FormattedValue, String)
Dim hasError As Boolean = False
If (Not value Is Nothing) AndAlso (value.Length > 5) Then
Me.ToolTip1.ToolTipIcon = ToolTipIcon.Error
Me.ToolTip1.ToolTipTitle = "検証エラー"
Me.ToolTip1.IsBalloon = True
Me.ToolTip1.SetToolTip(gcMultiRow.EditingControl, "dummy")
Me.ToolTip1.Show("入力された文字数が5文字を超えています。", gcMultiRow.EditingControl, 0, currentCellRect.Height)
hasError = True
e.Cancel = True
End If
' エラーがない場合、バルーンチップを消去する
If (hasError = False) Then
Me.ToolTip1.Hide(Me)
Me.ToolTip1.RemoveAll()
End If
End If
End Sub
using GrapeCity.Win.MultiRow;
private void Form1_Load(object sender, EventArgs e)
{
gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Enter);
gcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveToNextCell, Keys.Enter);
}
private void gcMultiRow1_CellValidating(object sender, CellValidatingEventArgs e)
{
GcMultiRow gcMultiRow = (GcMultiRow)sender;
if (e.CellIndex == 0 && e.RowIndex == 0)
{
Rectangle currentCellRect = gcMultiRow.GetCellDisplayRectangle(e.RowIndex, e.CellIndex);
string value = (string)e.FormattedValue;
bool hasError = false;
if (value != null && value.Length > 5)
{
this.toolTip1.ToolTipIcon = ToolTipIcon.Error;
this.toolTip1.ToolTipTitle = "検証エラー";
this.toolTip1.IsBalloon = true;
this.toolTip1.SetToolTip(gcMultiRow.EditingControl, "dummy");
this.toolTip1.Show("入力された文字数が5文字を超えています。", gcMultiRow.EditingControl, 0, currentCellRect.Height);
hasError = true;
e.Cancel = true;
}
// エラーがない場合、バルーンチップを消去する
if (hasError == false)
{
this.toolTip1.Hide(this);
this.toolTip1.RemoveAll();
}
}
}
ユーザーが入力した値をコードによって整形するには、タイミングに応じて次のコードを使用します。
編集済みのセルの値を書き換える場合 |
編集中のセルの値を書き換える |
GcMultiRow.SetValue メソッド または Cell.Value プロパティ |
GcMultiRow.EditingControl.Text プロパティ または セル編集コントロール固有のメンバ |
セルの編集状態はGcMultiRow.IsEditingプロパティで確認できます。
セル編集コントロールによって値の入力を制限できる場合があります。たとえば、TextBoxCellは最大入力文字数、NumericUpDownCellは数値のみ、MaskedTextBoxCellは整形された文字列といった制限を提供しています。