How to: Add Custom Controls to the Data Sources Window
When you drag an item from the Data Sources window to a design surface to create a data-bound control, you can select the type of control that you create. Each item in the window has a drop-down list that displays the controls that you can choose from. The set of controls associated with each item is determined by the data type of the item. If the control that you want to create does not appear in the list, you can follow the instructions in this topic to add the control to the list.
For more information about selecting data-bound controls to create for items in the Data Sources window, see How to: Set the Control to be Created when Dragging from the Data Sources Window.
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.
Perform the following steps to add or remove controls from the list of available controls for items in the Data Sources window that have a specific data type.
To select the controls to be listed for a data type
Make sure that the WPF Designer or the Windows Forms Designer is open.
In the Data Sources window, click an item that is part of a data source you added to the window, and then click the drop-down menu for the item.
In the drop-down menu, click Customize. One of the following dialog boxes opens:
If the Windows Forms Designer is open, the Data UI Customization page of the Options dialog box opens.
If the WPF Designer is open, the Customize Control Binding dialog box opens.
In the dialog box, select a data type from the Data type drop-down list.
To customize the list of controls for a table or object, select [List].
To customize the list of controls for a column of a table or a property of an object, select the data type of the column or property in the underlying data store.
To customize the list of controls to display data objects that have user-defined shapes, select [Other]. For example, select [Other] if your application has a custom control that displays data from more than one property of a particular object.
In the Associated controls box, select each control 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.
If the control that you want to select does not appear in the Associated controls box, you must add the control to the list. For more information, see Adding Controls to the List of Associated Controls for a Data Type.
In the Data Sources window, click an item of the data type that you just associated one or more controls, and then click the drop-down menu for the item.
The controls you selected in the Associated controls box now appear in the drop-down menu for the item.
If you want to associate a control with a data type, but the control does not appear in the Associated controls box, you must add the control to the list. The control must be located in the current solution or in a referenced assembly, be available in the Toolbox, and have an attribute that specifies the control's data binding behavior.
To add controls to the list of associated controls
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.
The control must have one of the following attributes.
Implement this attribute on simple controls that display a single column (or property) of data, such as a TextBox.
Implement this attribute on controls that display lists (or tables) of data, such as a DataGridView.
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.
Open the Data UI Customization page of the Options dialog box (for Windows Forms) or open the Customize Control Binding dialog box (for WPF). For more information, see Customizing the List of Bindable Controls for a Data Type.
In the Associated controls box, the control that you just added to the Toolbox should now appear.
Only controls that are located within the current solution or in a referenced assembly (and that implement one of the data-binding attributes in the previous table) can be added 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 the design surface, and then drag the item to bind to from the Data Sources window onto the control.