Files
docs-desktop/dotnet-desktop-guide/framework/winforms/multiple-controls-bound-to-data-source-synchronized.md
T
Andy De George c0ba284473 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
2020-09-01 16:26:21 -07:00

3.8 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Ensure Multiple Controls Bound to the Same Data Source Remain Synchronized 03/30/2017
csharp
vb
controls [Windows Forms], binding multiple
controls [Windows Forms], synchronizing with data source
c2f0ecc6-11e6-4c2c-a1ca-0759630c451e

How to: Ensure Multiple Controls Bound to the Same Data Source Remain Synchronized

Oftentimes when working with data binding in Windows Forms, multiple controls are bound to the same data source. In some cases, it may be necessary to take extra steps to ensure that the bound properties of the controls remain synchronized with each other and the data source. These steps are necessary in two situations:

In the former case, you can use a xref:System.Windows.Forms.BindingSource to bind the data source to the controls. In the latter case, you use a xref:System.Windows.Forms.BindingSource and handle the xref:System.Windows.Forms.BindingSource.BindingComplete event and call xref:System.Windows.Forms.BindingManagerBase.EndCurrentEdit%2A on the associated xref:System.Windows.Forms.BindingManagerBase.

Example

The following code example demonstrates how to bind three controls—two text-box controls and a xref:System.Windows.Forms.DataGridView control—to the same column in a xref:System.Data.DataSet using a xref:System.Windows.Forms.BindingSource component. This example demonstrates how to handle the xref:System.Windows.Forms.BindingSource.BindingComplete event and ensure that when the text value of one text box is changed, the additional text box and the xref:System.Windows.Forms.DataGridView control are updated with the correct value.

The example uses a xref:System.Windows.Forms.BindingSource to bind the data source and the controls. Alternatively, you can bind the controls directly to the data source and retrieve the xref:System.Windows.Forms.BindingManagerBase for the binding from the form's xref:System.Windows.Forms.Control.BindingContext%2A and then handle the xref:System.Windows.Forms.BindingManagerBase.BindingComplete event for the xref:System.Windows.Forms.BindingManagerBase. For an example of how to do this, see the Help page about the xref:System.Windows.Forms.BindingManagerBase.BindingComplete event of xref:System.Windows.Forms.BindingManagerBase.

[!code-csharpSystem.Windows.Forms.BindingSourceMultipleControls#1] [!code-vbSystem.Windows.Forms.BindingSourceMultipleControls#1]

Compiling the Code

See also