Saturday, October 11, 2008  



 FarPoint Technologies
 (800) 645-5913

 fpsales@fpoint.com



     
 »Spread for Windows Forms » Product Tour » Data Binding » Data Bind

Previous Managing Data Binding Next

  Back to Top
 Binding to a Data Set
You can bind the control to a data set. When you bind the control 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.

// Bind the control to the data set
fpSpread1.DataSource = dbDataSet;

' Bind the control to the data set
FpSpread1.DataSource = dbDataSet


  Back to Top
 Adding an Unbound Row to the Sheet
Once you bind a sheet to a data set you might want to add an unbound row to contain additional data. The figure shows a sheet in a Spread control that contains data from a data set and an unbound row at the bottom that calculates the averages.

// Add an unbound row
fpSpread1.Sheets[0].AddUnboundRows(3, 1);

' Add an unbound row
FpSpread1.Sheets(0).AddUnboundRows(3, 1)


  Back to Top
 Customizing Column Headers
By default, sheets display the field names in the column headers when bound to a data set. If you prefer, you can change the text to display custom column names.

// Set custom text in the first column header
fpSpread1.Sheets[0].ColumnHeader.Cells[0, 0].Text = "Name";

' Set custom text in the first column header
FpSpread1.Sheets(0).ColumnHeader.Cells(0, 0).Text = "Name"


  Back to Top
 Customizing Cell Types
By default, when the control or sheet is bound to a data set, it sets the cell types for the bound rows based on the data in the data set. You can turn off this automatic cell type assignment and assign cell types yourself. For example, you could make the ID field read-only so the contents can not be edited. 

// Turn off automatic cell type assignment
fpSpread1.Sheets[0].DataAutoCellTypes = false;

' Turn off automatic cell type assignment
FpSpread1.Sheets(0).DataAutoCellTypes = False


  Back to Top
 Customizing Column and Field Binding
When a sheet is bound to a data set, columns are assigned to data set fields sequentially. That is, the first data field is assigned to column A, the second to column B, and so on. You can change the assignments to assign any field to any column or only show certain columns.

// Turn off automatic column and field mapping
fpSpread1.Sheets[0].AutoGenerateColumns = false;
// Set the fields for the columns
fpSpread1.Sheets[0].Columns[0].DataField = "Company";
fpSpread1.Sheets[0].Columns[1].DataField = "Country";

' Turn off automatic column and field mapping
fpSpread1.Sheets(0).AutoGenerateColumns = false
' Set the fields for the columns
fpSpread1.Sheets(0).Columns(0).DataField = "Company"
fpSpread1.Sheets(0).Columns(1).DataField = "Country"


  Back to Top
 Working with Hierarchical Data Display
Sheets can display relational data, such as from a relational database, in hierarchical views. To set up hierarchical data display, you first create a data set to hold the relational data, then define the relations between the data, and finally, set the Spread control to display the data as you want. You can also bind to a hierarchical collection.
  1. Create your data set.
  2. Set up the data relations between the data coming from the data set, for example, between tables coming from a relational database.
  3. Set the DataSource property of the FpSpread control or the SheetView object equal to the data set.
  4. Provide code in the ChildViewCreated event of the FpSpread control for displaying the parent and child views of the data. 
' Add a relationship to the dataset
ds.Relations.Add("Root", ds.Tables("Categories").Columns("CategoryID"), ds.Tables("Products").Columns("CategoryID"))
' Bind Spread
FpSpread1.DataSource = ds


Previous Managing Data Binding Next

    
 Have a question?
Have a Question? Ask Us!
Subscribe to the RSS feed!RSS Subscribe
 

 
Learn about the new Roadshow now!

Tour Home
Overview
Appearance
User Interaction
Cell Types
Formulas
Managing Data
Data Binding
Import/Export
Printing
Keyboard Interaction
Shapes
Models
Spread Designer
 
Map

Copyright © 1991-2007 FarPoint Technologies, Inc. All rights reserved. All names are property of their respective owners.