Delen via


How to: Add Custom Controls to the Data Sources Window

Items in the Data Sources window can be dragged onto empty areas of a form in a Windows application to create data-bound controls. Prior to dragging an item from the Data Sources window, you can select the type of control that will be created by this action. You do so by choosing the control you want from the item's drop-down list of associated controls.

The list of controls attached to each item in the Data Sources Window is determined by the data type of that item:

  • Tables (or collections when object binding) are represented as [List] types.

  • Columns (or public properties when object binding) are represented as the actual data type of the column or property.

  • Objects with user-defined shapes are represented as [Other]. For example, if your application has a custom control that displays data from more than one property of an object you would select the [Other] data type for your control.

    Note

    The drop-down list of associated controls in the Data Sources window is only available when a valid drop target (such as a form) is the active window. For example, you cannot select a control from the drop-down list when the Code Editor is the active window.

You can modify the list of controls associated with each data type by choosing Customize from the control list on any item in the Data Sources window. The list of Associated controls is determined by the available controls in the Toolbox that implement one of the following data-binding attributes: DefaultBindingPropertyAttribute, ComplexBindingPropertiesAttribute, or LookupBindingPropertiesAttribute.

In other words, you can add controls to the Data Sources window that are in the Toolbox. If a control is not in the Toolbox, you will need to add it to the Toolbox before it can be available to add to the list for any data type.

Note

Controls located inside Windows applications are available in the Data Sources window only within the same project that they are located in.

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.

Customizing the List of Associated Controls for a Data Type

To select the controls to be listed for a data type

  1. Choose Customize from the control list attached to any item in the Data Sources window.

    The Options dialog box appears with Data UI Customization page selected.

  2. Select a type from the Data type drop-down list.

  3. Select each control in the Associated controls box that you want to be available for the selected data type, or clear the selection of any controls that you want to remove from the list.

Adding Controls to the List of Associated Controls for a Data Type

To associate a control to a data type, the control must be located in a referenced assembly, be available in the Toolbox, and implement one of the following attributes:

Attribute

Description

DefaultBindingPropertyAttribute

Implement this attribute on simple controls that display a single column (or property) of data, such as a TextBox. For more information, see Walkthrough: Creating a User Control that Supports Simple Data Binding.

ComplexBindingPropertiesAttribute

Implement this attribute on controls that display lists (or tables) of data, such as a DataGridView. For more information, see Walkthrough: Creating a User Control that Supports Complex Data Binding.

LookupBindingPropertiesAttribute

Implement this attribute on controls that display lists (or tables) of data, but also need to present a single column or property, such as a ComboBox. For more information, see Walkthrough: Creating a User Control that Supports Lookup Databinding.

Note

The list could become unmanageable and contain too many unavailable controls, so Visual Studio has rules to keep this from happening. Only controls that are located within the current project or in referenced assemblies (and that implement one of the data-binding attributes in the above table) are available to add to the list of associated controls. To bind data to a custom control that is not available in the Data Sources window, drag the control from the Toolbox onto your form, and then drag the item to bind to from the Data Sources window onto the custom control. For more information, see How to: Bind Data to Existing Controls.

To add controls to the list of associated controls

  1. Add the desired control to the Toolbox by right-clicking the Toolbox and selecting Choose Items. For more information, see How to: Manipulate Toolbox Tabs.

  2. Open the Data UI Customization dialog box by selecting Customize from the control list attached to any item in the Data Sources window.

    The control you just added to the Toolbox should appear in the list of Associated controls.

See Also

Tasks

Walkthrough: Displaying Data on a Form in a Windows Application

How to: Connect to Data in a Database

How to: Set the Control to be Created when Dragging from the Data Sources Window

Walkthrough: Creating a User Control that Supports Simple Data Binding

Walkthrough: Creating a User Control that Supports Complex Data Binding

Walkthrough: Creating a User Control that Supports Lookup Databinding

Concepts

Displaying Data Overview

TableAdapter Overview

Dataset Designer

Data Sources Overview