Search Results for

    Show / Hide Table of Contents

    ExcelFile.CheckDataValidation Method

    Overloads

    • ExcelFile.CheckDataValidation(Int32, Int32)
    • ExcelFile.CheckDataValidation(Int32, Int32, Object, Boolean)

    ExcelFile.CheckDataValidation(Int32, Int32)

    Checks if the data in the cells where the data validation applies conforms to the data validation specifications.

    Syntax

    Namespace: FlexCel.Core

    public abstract TCellAddress[] CheckDataValidation(Int32 index, Int32 maxErrors)

    Parameters

    <-> Parameter Type Description
    index Int32 Position in the list of data validations. (1 based)
    maxErrors Int32 The maximum number of errors reported by this method. To avoid getting a too big list, set it to a number like 100. If set to 0 or a negative number, the full list of errors will be returned, which can be very big.

    Returns

    An array with the first maxErrors cells that do not conform to the data validation. And empty array if all the cells conform.

    See also

    • ExcelFile

    ExcelFile.CheckDataValidation(Int32, Int32, Object, Boolean)

    Returns -1 if the value complies with all the data validations at the cell in row, col, or the position of the data validation that causes the error if the value is not valid. The position returned is 1 based, and you can use GetDataValidationInfo to get all information of the data validation.

    When the parameter setIsValid is true and the data is valid, then this will also set the cell to value.

    Syntax

    Namespace: FlexCel.Core

    public abstract Int32 CheckDataValidation(Int32 row, Int32 col, Object value, Boolean setIfValid)

    Parameters

    <-> Parameter Type Description
    row Int32 Row for the cell where we would like to enter the value. (1 based)
    col Int32 Column for the cell where we would like to enter the value. (1 based)
    value Object Value that we want to check if valid.
    setIfValid Boolean When true, the we will also set the cell value if the condition is valid. When false, we will only check if the value is valid, but keep the old value on the cell.

    Returns

    -1 if the value is valid for the cell according with the data validations on it, the position of the data validation causing the error otherwise. The position returned is 1 based, and you can use GetDataValidationInfo to get all information of the data validation.

    Examples

    To set a value in a cell if valid, and if not show the error associated to this data validation, you could use code like:

        var xls = new XlsFile(sourceFileName, true);
        xls.ActiveSheetByName = "Sheet With Data";
    
        //We will try to enter the number 11 at cell (row, col).
        int dv = xls.CheckDataValidation(row, col, 11, true);
    
        if (dv > 0) //There was an error. The cell value is not modified
        {
            TDataValidationInfo dvInfo = xls.GetDataValidationInfo(dv);
            LogMessage(dvInfo.ErrorBoxText);
        }
    

    See also

    • ExcelFile
    In This Article
    Back to top FlexCel Studio for the .NET Framework v7.24.0.0
    © 2002 - 2025 tmssoftware.com