ComponentOne FlexGrid for WinForms
Binding to a Data Source
Data Binding > Binding to a Data Source

Without writing a line of code, you can easily bind C1FlexGrid to a data source using the Data Source Configuration Wizard in Visual Studio. There are two ways to access the wizard, either through the DataSource property in the Properties window or the Choose Data Source box in the C1FlexGrid Tasks menu. For more information on the C1FlexGrid Tasks menu, see C1FlexGrid Tasks Menu.

Clicking the drop-down arrow next to either the DataSource property in the Properties window or the Choose Data Source box in the C1FlexGrid Tasks menu allows you to select from a list of available data sources or to add a data source to your project. To add a data source to your project, click Add Project Data Source to open the Data Source Configuration Wizard.


The Data Source Configuration Wizard walks you through adding a data source step by step. The Choose a Data Source Type page allows you to choose which type of application you would like to gather information from. The default selection is Database.

On the Choose Your Data Connection page, you can specify the location of the database. If you have not already connected to the database, you can specify a new connection by clicking the New Connection button. Clicking the New Connection button opens the Add Connection dialog box where you can browse to the location of your database and test the connection.

Mobile device users click here for additional information.

If you are using the Mobile edition of FlexGrid for WinForms, in the Add Connection dialog box, change the Data source to one that is supported by the Compact Framework, such as the .NET Framework Data Provider for SQL Server Mobile Edition.


Then you can use a supported database, for example, a SQL Server Mobile Edition Database. Microsoft provides a Northwind.sdf, by default, in the C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0 folder for Microsoft Visual Studio 2005.

The wizard saves and names your connection on the Save the Connection String to the Application Configuration File page. On this page you can specify a name or use the default provided by the wizard.

On the Choose Your Database Objects page you can specify which tables and fields you want to include in your DataSet. You can also provide a name for your DataSet or use the default provided by the wizard.

The wizard creates the DataSet, BindingSource, and TableAdapter, and adds them to your project. Click the drop-down arrow again next to the DataSource property or the Choose Data Source box in the C1FlexGrid Tasks menu and then select the data source. If you double-click the form, you will also notice that the code to fill the database is automatically generated in the Form_Load event.

See Also