Udostępnij za pośrednictwem


How to: Bind Data to Existing Controls

You can drag items from the Data Sources Window onto existing controls (controls already on a form) at any time during the development process to bind the control to data. When you drag an item from the Data Sources window onto a control, the control is then bound to that data. A control that is already bound to data has its data bindings reset to the item most recently dragged onto it.

Note

To be valid drop targets, controls must be capable of displaying the underlying data type of the item dragged onto it from the Data Sources window. For example, it is not valid to drag an item that has a data type of DateTime onto a CheckBox, because the CheckBox is not capable of displaying a date.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To bind an existing control to data in a data source

  1. Open the form in the Windows Forms Designer.

  2. Expand a table or object in the Data Sources window to display its individual columns or properties.

    Note

    To open the Data Sources window, click Show Data Sources on the Data menu. For more information, see How to: Open the Data Sources Window.

  3. Drag the desired item from the Data Sources window onto an existing control.

    The control is now bound to that selected item.

See Also

Tasks

Walkthrough: Displaying Data on a Form in a Windows Application

How to: Connect to Data in a Database

Concepts

What's New in Data

Dataset Designer

Data Sources Overview

Reference

BindingSource Component Overview

Other Resources

Data Walkthroughs

BindingNavigator Control (Windows Forms)

Validating Data