PowerTools MultiRow for Windows Forms 8.0J
RegularExpressionValidator クラス
メンバ  使用例 

指定した値が特定の正規表現と一致するかどうかを検証できる特別なCellValidatorを表します。
構文
Public Class RegularExpressionValidator 
   Inherits CellValidator
   Implements INamedObject 
public class RegularExpressionValidator : CellValidator, INamedObject  
解説
このCellValidatorは、検証する値の文字列表現が指定した正規表現と厳密に一致するかどうかを検証します。
使用例
次のサンプルコードは、RegularExpressionValidatorを使用して、入力値が、通貨値を示すExpressionと一致するかどうかを検証します。Cellに「-!2.05」と入力してから現在のセルを別のRowに移動しようとすると、フォーカスが動きません。これは、入力値がExpressionと一致せず、FocusProcessが実行されるためです。「-12.05」と入力すると、正常にフォーカスを移動できます。このサンプルコードは、CellValidatorに示されている詳細なコード例の一部を抜粋したものです。
void setRegularExpressionValidator_Click(object sender, EventArgs e)
{
    Template template = Template.CreateGridTemplate(1);

    RegularExpressionValidator regularExpressionValidator = new RegularExpressionValidator();
    //Define a regular expression for currency values.
    regularExpressionValidator.Expression = @"^-?\d+(\.\d{2})?$";
    regularExpressionValidator.RegexOptions = System.Text.RegularExpressions.RegexOptions.CultureInvariant;

    FocusProcess focusProcess = new FocusProcess();
    focusProcess.PreventFocusLeave = true;
    //When CurrentCell move to another Row, the action will be done.
    focusProcess.DoActionReason = ValidateReasons.RowValidating;

    regularExpressionValidator.Actions.Add(focusProcess);

    template.Row.Cells[0].Validators.Add(regularExpressionValidator);

    this.gcMultiRow1.Template = template;
    label .Text = @"The RegularExpressionValidator.Expression is '^-?\d+(\.\d{2})?$', which expresses one currency value, input '-!2.05', then move CurrentCell to another Row to trigger validation(DoActionReasion is RowValidating), You will find the focus cannot move out, input '-12.05',the focus can move to another Row.";
}
Private Sub setRegularExpressionValidator_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setRegularExpressionValidator.Click
    Dim template As Template = template.CreateGridTemplate(1)

    Dim regularExpressionValidator As New RegularExpressionValidator()
    'Define a regular expression for currency values.
    regularExpressionValidator.Expression = "^-?\d+(\.\d{2})?$"
    regularExpressionValidator.RegexOptions = System.Text.RegularExpressions.RegexOptions.CultureInvariant

    Dim focusProcess As New FocusProcess()
    focusProcess.PreventFocusLeave = True
    'When CurrentCell move to another Row, the action will be done.
    focusProcess.DoActionReason = ValidateReasons.RowValidating

    regularExpressionValidator.Actions.Add(focusProcess)

    template.Row.Cells(0).Validators.Add(regularExpressionValidator)

    Me.gcMultiRow1.Template = template
    label.Text = "The RegularExpressionValidator.Expression is '^-?\d+(\.\d{2})?$', which expresses one currency value, input '-!2.05', then move CurrentCell to another Row to trigger validation(DoActionReasion is RowValidating), You will find the focus cannot move out, input '-12.05',the focus can move to another Row."
End Sub
継承階層

System.Object
   GrapeCity.Win.MultiRow.CellValidator
      GrapeCity.Win.MultiRow.RegularExpressionValidator

参照

RegularExpressionValidator メンバ
GrapeCity.Win.MultiRow 名前空間
CellValidator クラス

 

 


© 2008-2015 GrapeCity inc. All rights reserved.