TextBoxCell で数値の入力を検証する方法
対象製品
MultiRow for Windows Forms 5.0J
詳細
GcMultiRow.CellValidating イベントを使用すると、セルに入力された値を検証できます。次のコードは、TextBoxCell に数字以外の文字が入力されたとき、セルにエラーテキストを設定します。
[Visual Basic]
[C#]
参考:
[Visual Basic]
Imports GrapeCity.Win.MultiRow
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 TypeOf gcMultiRow.CurrentCell Is TextBoxCell Then
If Not e.FormattedValue Is Nothing Then
Const numbers As String = "1234567890"
Dim value As String = e.FormattedValue.ToString()
For i As Integer = 0 To value.Length - 1
If numbers.IndexOf(value(i)) < 0 Then
gcMultiRow.CurrentCell.ErrorText = "数値以外の文字が含まれています"
Return
End If
Next
gcMultiRow.CurrentCell.ErrorText = String.Empty
End If
End If
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 TypeOf gcMultiRow.CurrentCell Is TextBoxCell Then
If Not e.FormattedValue Is Nothing Then
Const numbers As String = "1234567890"
Dim value As String = e.FormattedValue.ToString()
For i As Integer = 0 To value.Length - 1
If numbers.IndexOf(value(i)) < 0 Then
gcMultiRow.CurrentCell.ErrorText = "数値以外の文字が含まれています"
Return
End If
Next
gcMultiRow.CurrentCell.ErrorText = String.Empty
End If
End If
End Sub
[C#]
using GrapeCity.Win.MultiRow;
private void gcMultiRow1_CellValidating(object sender, GrapeCity.Win.MultiRow.CellValidatingEventArgs e)
{
GcMultiRow gcMultiRow = (GcMultiRow)sender;
if (gcMultiRow.CurrentCell is TextBoxCell)
{
if (e.FormattedValue != null)
{
const string numbers = "1234567890";
string value = e.FormattedValue.ToString();
for (int i = 0; i < value.Length; i++)
{
if (numbers.IndexOf(value[i]) < 0)
{
gcMultiRow.CurrentCell.ErrorText = "数値以外の文字が含まれています";
return;
}
}
gcMultiRow.CurrentCell.ErrorText = string.Empty;
}
}
}
private void gcMultiRow1_CellValidating(object sender, GrapeCity.Win.MultiRow.CellValidatingEventArgs e)
{
GcMultiRow gcMultiRow = (GcMultiRow)sender;
if (gcMultiRow.CurrentCell is TextBoxCell)
{
if (e.FormattedValue != null)
{
const string numbers = "1234567890";
string value = e.FormattedValue.ToString();
for (int i = 0; i < value.Length; i++)
{
if (numbers.IndexOf(value[i]) < 0)
{
gcMultiRow.CurrentCell.ErrorText = "数値以外の文字が含まれています";
return;
}
}
gcMultiRow.CurrentCell.ErrorText = string.Empty;
}
}
}
参考:
- InputManCell の GcTextBoxCell を使用すると、入力可能文字種を指定できます。(GcTextBoxCell.Format プロパティ)
関連情報
この文書は、以前は次のFAQ IDで公開されていました : 11296