Search code examples
c#spreadsheetgear

SpreadsheetGear.ValidationType.List turn off


I have a spreadsheetgear validation type list on one of the columns in a spreadsheet. The issue I have is when I reload the spreadsheet with different sets of data, I get an error that validation already exists. I don't know how to turn off the validation before reloading the new set of data. Please help.


Solution

  • If I understand the scenario correctly, you could either:

    1) Use IValidation.Delete() to remove existing validation to the range prior to adding new validation.

    worksheet.Cells["A:A"].Validation.Delete(); 
    worksheet.Cells["A:A"].Validation.Add(...);
    

    2) Instead of all out deleting the old one, modify the existing IRange.Validation object to fit your new data set. You would use IValidation.Modify(...) to do this.