# Binding a Cell Range in Spread to an External Data Source

Understand how to prevent automatic data type matching between the external data source and Spread component by setting DataAutoCellTypes to False.

## Content

You can bind a cell range in Spread to an external data source. To do this, use the [SpreadDataBindingAdpater](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Data.SpreadDataBindingAdapter.html) class to create a connection between the Spread component and the data source and use the [MapperInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Data.MapperInfo.html) class to map the cell range to the range in the data source.
![Binding a Cell Range in Spread to an External Data Source](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/diagram-extdatatospread.png)
If you add or remove a column from the data source when bound to a cell range, the Spread component does not automatically update.
The data source and the cell range in the Spread are controlled by the [MapperInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Data.MapperInfo.html) class. They synchronize with each other via row synchronization. If the user adds or removes any row in the cell range, it will affect the data source and vice versa. If the user adds a new row right below the existing bound cell range, the cell range will expand one row and make the [MapperInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Data.MapperInfo.html) class and data source expand and vice versa. If the new row is added outside of the bound area, then it is not added to the bound range.
By default the Spread component tries to match the data type of the external data source to the cell type of Spread. You can set [DataAutoCellTypes](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Data.SpreadDataBindingAdapter.DataAutoCellTypes.html) to False to prevent this. The following table shows the default cell type that is used based on the type of data.

| **Data Type** | **Cell Type** |
| --------- | --------- |
| Boolean | Check box cell |
| DateTime | Date time cell |
| Double, Single, Decimal | Number cell |
| Int16, Int32, and so on | Number cell |
| String | Text cell |
| Other | General cell |

For more information, refer to the [SpreadDataBindingAdpater](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Data.SpreadDataBindingAdapter.html) class and the [MapperInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Data.MapperInfo.html) class in the API reference.

## Using Code

1. Create your data set.
2. Create a new **SpreadDataBindingAdapter** object.
3. Set the **Spread** object to the adapter.
4. Set the sheet name.
5. Create the **MapperInfo** object and link it to the adapter.
6. Set the **FillSpreadDataByDataSource** method.

## Example

This example code binds a single cell range to a data source. The example requires that you create a datasource object named "dt".

```csharp
FarPoint.Win.Spread.Data.SpreadDataBindingAdapter data = new FarPoint.Win.Spread.Data.SpreadDataBindingAdapter();
// Assign the datasource to a data table
data.DataSource = dt;
data.Spread = fpSpread1;
data.SheetName = "Sheet1";
data.MapperInfo = new FarPoint.Win.Spread.Data.MapperInfo(3, 2, 1, 1);
data.FillSpreadDataByDataSource();
```

```vbnet
' Create an adapter.
Dim data As New FarPoint.Win.Spread.Data.SpreadDataBindingAdapter
' Assign the datasource to a data table
data.DataSource = dt
data.Spread = fpSpread1
data.SheetName = "Sheet1"
data.MapperInfo = New FarPoint.Win.Spread.Data.MapperInfo(3, 2, 1, 1)
data.FillSpreadDataByDataSource()
```

## See Also

[Binding Spread to an External Data Set](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-data-binding/spwin-databind/spwin-databind-howto)
[Binding a Cell Range in Spread as a Data Source to an External Control](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-data-binding/spwin-databind/spwin-databind-customrange)
[Binding a Combo Box to a DataReader](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-data-binding/spwin-databind/spwin-databind-comboreader)