* 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
7.0 KiB
title, ms.date, helpviewer_keywords, ms.assetid
| title | ms.date | helpviewer_keywords | ms.assetid | ||||
|---|---|---|---|---|---|---|---|
| BindingSource Component Overview | 03/30/2017 |
|
be838caf-fcb0-4b68-827f-58b2c04b747f |
BindingSource Component Overview
The xref:System.Windows.Forms.BindingSource component is designed to simplify the process of binding controls to an underlying data source. The xref:System.Windows.Forms.BindingSource component acts as both a conduit and a data source for other controls to bind to. It provides an abstraction of your form's data connection while passing through commands to the underlying list of data. Additionally, you can add data directly to it, so that the component itself functions as a data source.
BindingSource Component as an Intermediary
The xref:System.Windows.Forms.BindingSource component acts as the data source for some or all of the controls on the form. In Visual Studio, the xref:System.Windows.Forms.BindingSource can be bound to a control by means of the DataBindings property, which is accessible from the Properties window. Also see How to: Bind Windows Forms Controls with the BindingSource Component Using the Designer.
You can bind the xref:System.Windows.Forms.BindingSource component to both simple data sources, like a single property of an object or a basic collection like xref:System.Collections.ArrayList, and complex data sources, like a database table. The xref:System.Windows.Forms.BindingSource component acts as an intermediary that provides binding and currency management services. At design time or run time, you can bind a xref:System.Windows.Forms.BindingSource component to a complex data source by setting its xref:System.Windows.Forms.BindingSource.DataSource%2A and xref:System.Windows.Forms.BindingSource.DataMember%2A properties to the database and table, respectively. The following illustration demonstrates where the xref:System.Windows.Forms.BindingSource component fits into the existing data-binding architecture.
Note
At design time, some actions, like dragging a database table from a data window onto a blank form, will create the xref:System.Windows.Forms.BindingSource component, bind it to the underlying data source, and add data-aware controls all in one operation. Also see Bind Windows Forms controls to data in Visual Studio.
BindingSource Component as a Data Source
If you start adding items to the xref:System.Windows.Forms.BindingSource component without first specifying a list to be bound to, the component will act like a list-style data source and accept these added items.
Additionally, you can write code to provide custom "AddNew" functionality by means of the xref:System.Windows.Forms.BindingSource.AddingNew event, which is raised when the xref:System.Windows.Forms.BindingSource.AddNew%2A method is called prior to the item being added to the list. For more information, see BindingSource Component Architecture.
Navigation
For users that need to navigate the data on a form, the xref:System.Windows.Forms.BindingNavigator component enables you to navigate and manipulate data, in coordination with a xref:System.Windows.Forms.BindingSource component. For more information, see BindingNavigator Control.
Data Manipulation
The: xref:System.Windows.Forms.BindingSource acts as a xref:System.Windows.Forms.CurrencyManager for all of its bindings and can, therefore, provide access to currency and position information regarding the data source. The following table shows the members that the xref:System.Windows.Forms.BindingSource component provides for accessing and manipulating the underlying data.
Sorting and Filtering
Usually, you should work with an ordered or filtered view of the data source. The following table shows the members that the xref:System.Windows.Forms.BindingSource component data source provides.
| Member | Description |
|---|---|
| xref:System.Windows.Forms.BindingSource.Sort%2A property | If the data source is an xref:System.ComponentModel.IBindingList, gets or sets a column name used for sorting and sort order information. If the data source is an xref:System.ComponentModel.IBindingListView and supports advanced sorting, gets multiple column names used for sorting and sort order information |
| xref:System.Windows.Forms.BindingSource.Filter%2A property | If the data source is an xref:System.ComponentModel.IBindingListView, gets or sets the expression used to filter which rows are viewed. |
