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

指定した値とComparedValueが特定の比較関係を満たすかどうかを検証できる特別なCompareValueBaseValidatorを表します。
構文
Public Class CompareValueValidator 
   Inherits CompareValueBaseValidator
   Implements INamedObject 
public class CompareValueValidator : CompareValueBaseValidator, INamedObject  
解説
検証する値からComparedValueを引いた結果をCompareValueBaseValidator.DifferenceValueと比較できます。
使用例
次のサンプルコードは、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
継承階層

System.Object
   GrapeCity.Win.MultiRow.CellValidator
      GrapeCity.Win.MultiRow.CompareValueBaseValidator
         GrapeCity.Win.MultiRow.CompareValueValidator

参照

CompareValueValidator メンバ
GrapeCity.Win.MultiRow 名前空間
CellValidator クラス
CompareValueBaseValidator クラス
CompareCellValidator クラス

 

 


© 2008-2015 GrapeCity inc. All rights reserved.