Spread Windows Forms 7.0 Product Documentation
Binding Spread to an External Data Set
Support Options
Spread Windows Forms 7.0 Product Documentation > Developer's Guide > Managing Data Binding > Binding to Data > Binding Spread to an External Data Set

Glossary Item Box

You can bind the Spread component to a data set. When you bind the component using the default settings, data from the data set is read into the columns and rows of the sheet to which you bind the data. Columns are associated with fields, and rows represent each record in the data set.

You can also bind a sheet, column, or cell range.

The following instructions provide the code necessary to bind the Spread component to a data set. For a tutorial that can introduce you to the procedure for data binding, refer to the Tutorial: Binding to a Corporate Database.

For more information, refer to the AddRowToDataSource and BindDataColumn methods.

If you want to re-order the columns in a data set, move around the columns in the Spread after the bind. Use the BindDataColumn method in the SheetView class to do this.

There are many alternative ways to set up data binding. To learn more about data binding in Visual Studio .NET, consult the Visual Studio .NET documentation.

Using the Properties Window

  1. Create your data set.
  2. In the Properties window select the Spread component.
    1. To set the data source for the component, set the DataSource property.
    2. To set the data source for the sheet, select the Sheets property for the Spread component, click the button to display the SheetView Collection Editor, select the sheet for which to set the data source, then set the DataSource property for that sheet.

Using Code

  1. Create your data set.
  2. Set the FpSpread DataSource or SheetView DataSource property equal to the data set.

Example

This example code binds the Spread component to a data set.

C# Copy Code
// Bind the component to the data set.
fpSpread1.Sheets[0].AutoGenerateColumns = false;
fpSpread1.Sheets[0].DataSource = dbDataSet;
fpSpread1.Sheets[0].ColumnCount = 2;
fpSpread1.Sheets[0].BindDataColumn(0, "ID");
fpSpread1.Sheets[0].BindDataColumn(1, "Description");
// Bind a cell range
// FarPoint.Win.Spread.Data.SpreadDataBindingAdapter data = new FarPoint.Win.Spread.Data.SpreadDataBindingAdapter();
//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
' Bind the component to the data set.
FpSpread1.Sheets(0).AutoGenerateColumns = False
FpSpread1.Sheets(0).DataSource = dbDataSet
FpSpread1.Sheets(0).ColumnCount = 2
FpSpread1.Sheets(0).BindDataColumn(0, "ID")
FpSpread1.Sheets[0].BindDataColumn(1, "Description")
' Bind a cell range
'Dim data As New FarPoint.Win.Spread.Data.SpreadDataBindingAdapter
'data.DataSource = dt
'data.Spread = FpSpread1
'data.SheetName = "Sheet1"
'data.MapperInfo = New FarPoint.Win.Spread.Data.MapperInfo(3, 2, 1, 1)
'data.FillSpreadDataByDataSource()

© 2002-2014 ComponentOne, a division of GrapeCity. All Rights Reserved.