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.v26.1.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();
}
See Also