Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / Data Binding / Binding to Data / Binding Spread to an External Data Set
In This Topic
    Binding Spread to an External Data Set
    In This Topic

    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 (Visual Studio 2013 or later).

    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.
      • To set the data source for the component, set the DataSource property.
      • To set the data source for the sheet,
      1. Select the Sheets property for the Spread component.
      2. Click the button to display the SheetView Collection Editor.
      3. Select the sheet for which to set the data source.
      4. 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 named "dbDataSet".

    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");
    
    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")
    
    See Also