Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-share-bound-data-across-forms-using-the-bindingsource-component.md
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

2.4 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Share Bound Data Across Forms Using the BindingSource Component 03/30/2017
csharp
vb
examples [Windows Forms], BindingSource component
data binding [Windows Forms], sharing data across forms
BindingSource component [Windows Forms], examples
BindingSource [Windows Forms], using with multiple forms
a1a49630-db9c-4485-b888-1f62a373a4f7

How to: Share Bound Data Across Forms Using the BindingSource Component

You can easily share data across forms using the xref:System.Windows.Forms.BindingSource component. For example, you may want to display one read-only form that summarizes the data-source data and another editable form that contains detailed information about the currently selected item in the data source. This example demonstrates this scenario.

Example

The following code example demonstrates how to share a xref:System.Windows.Forms.BindingSource and its bound data across forms. In this example, the shared xref:System.Windows.Forms.BindingSource is passed to the constructor of the child form. The child form allows the user to edit the data for the currently selected item in the main form.

Note

The xref:System.Windows.Forms.BindingSource.BindingComplete event for the xref:System.Windows.Forms.BindingSource component is handled in the example to ensure that the two forms remain synchronized. For more information about why this is done, see How to: Ensure Multiple Controls Bound to the Same Data Source Remain Synchronized.

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

Compiling the Code

This example requires:

  • References to the System, System.Windows.Forms, System.Drawing, System.Data, and System.Xml assemblies.

See also