Spread Windows Forms 8.0 Product Documentation > Developer's Guide > Managing Data Binding > Binding to Data > Binding Spread to an External Data Set |
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.
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() |