Version

SetConstraintFormula(String,String,WorkbookFormat,CellReferenceMode,CultureInfo) Method

Sets the constraint formula used to validate the cell value.
Syntax
public void SetConstraintFormula( 
   string constraintFormula,
   string address,
   WorkbookFormat format,
   CellReferenceMode cellReferenceMode,
   CultureInfo culture
)

Parameters

constraintFormula
The validation formula to use for the rule.
address
The address of the cell or region that serves as the basis for relative references, or null to use the top-left cell of the worksheet.
format
The workbook format with which to parse address.
cellReferenceMode
The cell reference mode with which to parse address.
culture
The culture to use when parsing the formula string.
Exceptions
ExceptionDescription
System.ArgumentNullExceptionOccurs when constraintFormula is null and the rule is currently applied to a Worksheet.
FormulaParseExceptionOccurs when constraintFormula is not a valid formula.
System.ArgumentExceptionOccurs when address is not a valid cell or regions address.
System.ComponentModel.InvalidEnumArgumentExceptionOccurs when format is not defined in the WorkbookFormat enumeration.
System.ComponentModel.InvalidEnumArgumentExceptionOccurs when cellReferenceMode is not defined in the CellReferenceMode enumeration.
Remarks

The way in which the cell value is compared to the constraint formula's value is determined by the ValidationOperator as well as the ValueConstraintDataValidationRule.ValidationCriteria.

Depending on the ValidationCriteria of the rule, either the cell value itself or the length of the cell value's text equivalent is compared to the constraint formula's value.

The address passed in is only needed if relative addresses are used in the the formula. When the data validation rule is applied to cells or regions, the references in the formula used by each individual cell will be shifted by the offset of the cell to the passed in address. For example, consider the formula specified is =B1 and the specified address is A1. If the data validation rule is then applied to the A5 cell, the formula is will use is =B5. However, if the references in the formula are absolute, such as =$B$1, the same formula will be applied regardless of the specified address.

address can be any valid cell or region reference on a worksheet. If a region address is specified, the top-left cell or the region is used. The cell or region specified does not need to have the data validation rule applied to it. Any reference is allowed.

Requirements

Target Platforms: Android 4.4+, iOS 8+

Development Environments: Visual Studio 2015+, Visual Studio for Mac Preview, Xamarin for Visual Studio 4.2+

See Also