* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
3.2 KiB
title, ms.date, helpviewer_keywords, ms.assetid
| title | ms.date | helpviewer_keywords | ms.assetid | |||
|---|---|---|---|---|---|---|
| Bind Controls with the BindingSource Component Using the Designer | 03/30/2017 |
|
391ae170-de5c-40f8-8233-91cb2ee4683a |
How to: Bind Windows Forms Controls with the BindingSource Component Using the Designer
After you have added controls to your form and determined the user interface for your application, you can bind the controls to a data source, so that, at run time, users can alter and save data related to the application.
Binding a control or series of controls in Windows Forms is most easily accomplished using the xref:System.Windows.Forms.BindingSource control as a bridge between the controls on the form and the data source.
One or more controls on a form can be bound to data; in the following procedure, a xref:System.Windows.Forms.TextBox control is bound to a data source.
To complete the procedure, it is assumed that you will bind to a data source derived from a database. For more information on creating data sources from other stores of data, see Add new data sources.
To bind a control at design time
-
Drag a xref:System.Windows.Forms.TextBox control on to the form.
-
In the Properties window:
-
Expand the (DataBindings) node.
-
Click the arrow next to the xref:System.Windows.Forms.TextBox.Text%2A property.
The DataSource UI type editor opens.
If a data source has previously been configured for the project or form, it will appear.
-
-
Click Add Project Data Source to connect to data and create a data source.
-
On the Data Source Configuration Wizard welcome page, click Next.
-
On the Choose a Data Source Type page, select Database.
-
On the Choose Your Data Connection page, select a data connection from the list of available connections. If your desired data connection is not available select New Connection to create a new data connection.
-
Select Yes, save the connection to save the connection string in the application configuration file.
-
Select the database objects to bring into your application. In this case, select a field in a table that you would like the xref:System.Windows.Forms.TextBox to display.
-
Replace the default dataset name if you want.
-
Click Finish.
-
In the Properties window, click the arrow next to the xref:System.Windows.Forms.TextBox.Text%2A property again. In the DataSource UI type editor, select the name of the field to bind the xref:System.Windows.Forms.TextBox to.
The DataSource UI type editor closes and the data set, xref:System.Windows.Forms.BindingSource and table adapter specific to that data connection are added to your form.