Syncfusion.XlsIO.Base
Example 


DataRange Property (IDataValidation)

Gets or sets the Range of possible values. The list of DataRange cell values are set as dropdown list of DataValidation Range.
Syntax
'Declaration
 
Property DataRange As IRange
'Usage
 
Dim instance As IDataValidation
Dim value As IRange
 
instance.DataRange = value
 
value = instance.DataRange
IRange DataRange {get; set;}
Remarks
In Output of an excel the list of DataRange cell values are in dropdown list of DataValidation Range. To know more about DataRange property refer this link.
Example
The following code illustrates the use of DataRange property.
using Syncfusion.XlsIO;
using System.Drawing;
             
class Example
{
    static void Main()
    {
        using (ExcelEngine excelEngine = new ExcelEngine())
        {
           //Create a worksheet.        
           IApplication application = excelEngine.Excel;
           application.DefaultVersion = ExcelVersion.Excel2013;
           IWorkbook workbook = application.Workbooks.Create(1);
           IWorksheet worksheet = workbook.Worksheets[0];
           worksheet.Range["A2"].CellStyle.Color = Color.LightGray;
           worksheet.Range["A1"].Text = "Select the Day in A2";
           worksheet.Range["A1"].AutofitColumns();
           worksheet.Range["D1"].Text = "Days in a Week";
           worksheet.Range["D2"].Text = "Monday";
           worksheet.Range["D3"].Text = "Tuesday";
           worksheet.Range["D4"].Text = "Wednesday";
           worksheet.Range["D5"].Text = "Thursday";
           worksheet.Range["D6"].Text = "Friday";
           worksheet.Range["D7"].Text = "Saturday";
           worksheet.Range["D8"].Text = "Sunday";
           worksheet.Range["D1"].AutofitColumns();
            
           // DataValidation in Worksheet Range
           IDataValidation validation = worksheet.Range["A2"].DataValidation;
           validation.DataRange = worksheet.Range["D2:D8"]; //DataRange for Data Validation
           validation.IsEmptyCellAllowed = true;
           validation.IsSuppressDropDownArrow = false;
            
           workbook.SaveAs("DataValidation.xlsx");
           workbook.Close();
           excelEngine.Dispose();
        }
     }
 }
AssemblyVersion

Syncfusion.XlsIO.Base: 17.2460.0.34

See Also