Spread Windows Forms 8.0 Product Documentation
Binding a Cell Range in Spread to an External Data Source

You can bind a cell range in Spread to an external data source. To do this, use the SpreadDataBindingAdpater class to create a connection between the Spread component and the data source and use the MapperInfo class to map the cell range to the range in the data source.

Binding a Cell Range in Spread to an External Data Source

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 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 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 to false to prevent this. The following table shows the 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, etc.

Number cell

String

Text cell

Other

General cell

For more information, refer to the SpreadDataBindingAdapter class and the MapperInfo 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.

C#
Copy Code
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();
VB
Copy Code
' 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

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options | Documentation Feedback