GrapeCity SPREAD for Windows Forms 11.0J
値の比較による検証

セル値を、別の値と比較するバリデータを作成できます。値を比較できるのは、DateTime型、TimeSpan型、またはDecimal型(数値型)の値です。

入力値が無効である場合は、検証エラーが発生します。セルにテキストチップを追加して、無効な値であることを警告するなど、関連するアクションを作成することもできます。

このバリデータを作成するには、CompareValueValidatorクラスを使用します。TipNotifyなどの通知タイプを指定します。次に、AddValidatorsメソッドを使用して、特定のセル範囲にバリデータを追加します。

次の図では、セルに、無効な入力値を示すテキストチップが表示されています。

サンプルコード

次のサンプルコードは、5以下の値が入力された場合に、アイコンを表示します。

C#
コードのコピー
// セル1,1に値を入力します。
FarPoint.Win.Spread.TipNotify tnote = new FarPoint.Win.Spread.TipNotify();
tnote.ToolTipText = "Greater than 5";
tnote.ToolTipTitle = "Error";
tnote.ToolTipIcon = ToolTipIcon.Error;
FarPoint.Win.Spread.CompareValueValidator compare = new FarPoint.Win.Spread.CompareValueValidator();
compare.ComparedOperator = FarPoint.Win.Spread.ValidateComparisonOperator.GreaterThan;
compare.ComparedValue = 5;
compare.Actions.Add(tnote);
fpSpread1.Sheets[0].AddValidators(new FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), compare);
Visual Basic
コードのコピー
' セル1,1に値を入力します。
Dim tnote As New FarPoint.Win.Spread.TipNotify()
tnote.ToolTipText = "Greater than 5"
tnote.ToolTipTitle = "Error"
tnote.ToolTipIcon = ToolTipIcon.Error
Dim compare As New FarPoint.Win.Spread.CompareValueValidator()
compare.ComparedOperator = FarPoint.Win.Spread.ValidateComparisonOperator.GreaterThan
compare.ComparedValue = 5
compare.Actions.Add(tnote)
FpSpread1.Sheets(0).AddValidators(New FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), compare)
関連トピック

 

 


© 2004-2018, GrapeCity Inc. All rights reserved.