mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-07 23:43:19 +02:00
Initial winforms content migrated (#18)
* 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
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
---
|
||||
title: Bind Controls with the BindingSource Component Using the Designer
|
||||
ms.date: "03/30/2017"
|
||||
helpviewer_keywords:
|
||||
- "controls [Windows Forms], binding"
|
||||
- "BindingSource component [Windows Forms], binding controls"
|
||||
- "data binding [Windows Forms], BindingSource component"
|
||||
ms.assetid: 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](/visualstudio/data-tools/add-new-data-sources).
|
||||
|
||||
## To bind a control at design time
|
||||
|
||||
1. Drag a <xref:System.Windows.Forms.TextBox> control on to the form.
|
||||
|
||||
2. In the **Properties** window:
|
||||
|
||||
1. Expand the **(DataBindings)** node.
|
||||
|
||||
2. 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.
|
||||
|
||||
3. Click **Add Project Data Source** to connect to data and create a data source.
|
||||
|
||||
4. On the **Data Source Configuration Wizard** welcome page, click **Next**.
|
||||
|
||||
5. On the **Choose a Data Source Type** page, select **Database**.
|
||||
|
||||
6. 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.
|
||||
|
||||
7. Select **Yes, save the connection** to save the connection string in the application configuration file.
|
||||
|
||||
8. 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.
|
||||
|
||||
9. Replace the default dataset name if you want.
|
||||
|
||||
10. Click **Finish**.
|
||||
|
||||
11. 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.
|
||||
|
||||
## See also
|
||||
|
||||
- <xref:System.Windows.Forms.BindingSource>
|
||||
- <xref:System.Windows.Forms.BindingNavigator>
|
||||
- [Add new data sources](/visualstudio/data-tools/add-new-data-sources)
|
||||
- [Data Sources Window](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/6ckyxa83(v=vs.120))
|
||||
Reference in New Issue
Block a user