Skip to main content
Row

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

WorksheetDataBindingCollection.BindTableToDataSource(Object, CellRange, ExternalDataSourceOptions) Method

Creates a worksheet table from the specified range and binds it to the data source using the specified options.

Namespace: DevExpress.Spreadsheet

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

NuGet Package: DevExpress.Spreadsheet.Core

#Declaration

WorksheetTableDataBinding BindTableToDataSource(
    object dataSource,
    CellRange range,
    ExternalDataSourceOptions options
)

#Parameters

Name Type Description
dataSource Object

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

range CellRange

A CellRange object specifying the range of the worksheet table being created.

options ExternalDataSourceOptions

An ExternalDataSourceOptions object that contains options used to establish binding.

#Returns

Type Description
WorksheetTableDataBinding

A WorksheetTableDataBinding object that contains information about the data-bound worksheet table.

#Example

View Example

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

    // Remove all data bindings bound to the specified data source.
    sheet.DataBindings.Remove(weatherDatasource);

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

    // Create a table and bind the data source to the table.
    try {
        WorksheetTableDataBinding sheetDataBinding = sheet.DataBindings.BindTableToDataSource(weatherDatasource, bindingRange, dsOptions);
        sheetDataBinding.Table.Style = spreadsheetControl1.Document.TableStyles[BuiltInTableStyleId.TableStyleMedium14];

        // Adjust the column width.
        sheetDataBinding.Range.AutoFitColumns();
    }
    catch(Exception e) {
        MessageBox.Show(e.Message, "Binding Exception");
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the BindTableToDataSource(Object, CellRange, ExternalDataSourceOptions) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also