.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

WorksheetDataBindingCollection.BindToDataSource(Object, Int32, Int32, ExternalDataSourceOptions) Method

Binds the worksheet cell range to the specified data source using the specified options.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v20.2.Core.dll


WorksheetDataBinding BindToDataSource(
    object dataSource,
    int rowIndex,
    int columnIndex,
    ExternalDataSourceOptions options


Name Type Description
dataSource Object

A data source object whose data should be retrieved into the worksheet.

rowIndex Int32

An integer that is the row index of the top left cell in the binding range.

columnIndex Int32

An integer that is the column index of the top left cell in the binding range.

options ExternalDataSourceOptions

An ExternalDataSourceOptions object that contains options used to establish binding.


Type Description

A WorksheetDataBinding object that contains information about the data-bound range.


private void BindWeatherReportToRange(object weatherDatasource, CellRange bindingRange) {
    Worksheet sheet = spreadsheetControl1.Document.Worksheets[0];

    // Check for range conflicts.
    var dataBindingConflicts = sheet.DataBindings.
        Where(d => (d.Range.RightColumnIndex >= bindingRange.LeftColumnIndex) || (d.Range.BottomRowIndex >= bindingRange.TopRowIndex)) ;
    if (dataBindingConflicts.Count() > 0) {
        MessageBox.Show("Cannot bind the range to data.\r\nThe worksheet contains other binding ranges which may conflict.", "Range Conflict");

    // Specify the binding options.
    ExternalDataSourceOptions dsOptions = new ExternalDataSourceOptions();
    dsOptions.ImportHeaders = true;
    dsOptions.CellValueConverter = new MyWeatherConverter();
    dsOptions.SkipHiddenRows = true;

    // Bind the data source to the worksheet range.
    WorksheetDataBinding sheetDataBinding = sheet.DataBindings.BindToDataSource(weatherDatasource, bindingRange, dsOptions);

    // Adjust the column width.
See Also