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.v24.2.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
WorksheetDataBinding BindToDataSource(
object dataSource,
int rowIndex,
int columnIndex,
ExternalDataSourceOptions options
)
Parameters
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. |
Returns
Type | Description |
---|---|
WorksheetDataBinding | A WorksheetDataBinding object that contains information about the data-bound range. |
Example
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");
return;
}
// 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.
sheetDataBinding.Range.AutoFitColumns();
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the BindToDataSource(Object, Int32, Int32, 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.