PowerTools MultiRow for Windows Forms 8.0J
RequiredType プロパティ (CompareValueBaseValidator)
使用例 

指定した値に必要なSystem.Typeを取得または設定します。
構文
Public Property RequiredType As Type
public Type RequiredType {get; set;}

プロパティ値

指定した値に必要なSystem.Typeを表すSystem.Type値。既定値はnull 参照 (Visual Basicでは Nothing)です。
解説
RequiredTypeを新しい値に設定すると、DifferenceValueがnull 参照 (Visual Basicでは Nothing)に設定されます。
使用例
次のサンプルコードは、CompareValueValidatorを使用して、元の値が10より大きいかどうかを検証します。入力モードに入って何らかの値を入力し、[Enter]キーを押して編集を終了します。その後で、[Esc]キーを押してCancelRowを発生させると、元の値が9であるため、検証が失敗してシステムサウンドが再生されます。このサンプルコードは、CellValidatorに示されている詳細なコード例の一部を抜粋したものです。
void setCompareValueValidator_Click(object sender, EventArgs e)
{
    Template template = Template.CreateGridTemplate(1);

    CompareValueValidator compareValueValidator = new CompareValueValidator();
    //You should set the RequiredType first, then set other Properties.
    compareValueValidator.RequiredType = typeof(int);
    compareValueValidator.ComparedValue = 10;
    compareValueValidator.DifferenceValue = 0;
    compareValueValidator.ComparedOperator = ValidateComparisonOperator.GreaterThan;
    
    SoundNotify soundNotify = new SoundNotify();
    soundNotify.SoundType = SystemSoundType.Asterisk;
    //When cancel the whole Row editing, the old value will be restored.
    soundNotify.DoActionReason = ValidateReasons.CancelRow;

    compareValueValidator.Actions.Add(soundNotify);

    //When do the SoundNotify action, this value 9 will be validated.
    template.Row.Cells[0].Value = 9;
    template.Row.Cells[0].Validators.Add(compareValueValidator);

    this.gcMultiRow1.Template = template;
    label.Text = "The CompareValueValidator.ComparedValue is 10, DifferenceValue is 0, ComparedOperator is GreaterThan, input some value to Cell, press ENTER to commit value(not validate), then press ESC to trigger validation(DoActionReason is CancelRow), the old value 9 is restored and validated, validation failed, one Sound will be played";
}
Private Sub setCompareValueValidator_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setCompareValueValidator.Click
    Dim template As Template = template.CreateGridTemplate(1)

    Dim compareValueValidator As New CompareValueValidator()
    'You should set the RequiredType first, then set other Properties.
    compareValueValidator.RequiredType = GetType(Integer)
    compareValueValidator.ComparedValue = 10
    compareValueValidator.DifferenceValue = 0
    compareValueValidator.ComparedOperator = ValidateComparisonOperator.GreaterThan

    Dim soundNotify As New SoundNotify()
    soundNotify.SoundType = SystemSoundType.Asterisk
    'When cancel the whole Row editing, the old value will be restored.
    soundNotify.DoActionReason = ValidateReasons.CancelRow

    compareValueValidator.Actions.Add(soundNotify)

    'When do the SoundNotify action, this value 9 will be validated.
    template.Row.Cells(0).Value = 9
    template.Row.Cells(0).Validators.Add(compareValueValidator)

    Me.gcMultiRow1.Template = template
    label.Text = "The CompareValueValidator.ComparedValue is 10, DifferenceValue is 0, ComparedOperator is GreaterThan, input some value to Cell, press ENTER to commit value(not validate), then press ESC to trigger validation(DoActionReason is CancelRow), the old value 9 is restored and validated, validation failed, one Sound will be played"
End Sub
参照

CompareValueBaseValidator クラス
CompareValueBaseValidator メンバ

 

 


© 2008-2015 GrapeCity inc. All rights reserved.