Custom Data Controls Sample
The document is archived and information here might be outdated

Custom Data Controls Sample 

Download sample

This sample demonstrates how to use your own controls with the Data Sources window.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To open the sample file in Solution Explorer

  1. Click Download Sample.

    The File Download message box appears.

  2. Click Open, and on the left column of the zip folder window, click Extract all files.

    The Extraction Wizard opens.

  3. Click Next. You can change the directory that the files will be extracted to, and then click Next again.

  4. Make sure that the Show extracted files check box is selected, and click Finish.

  5. Double-click the sample's .sln file.

    The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.

To run this sample

  • Press F5.


This sample requires the Northwind sample database. For more information, see How to: Install and Troubleshoot Database Components for Samples.


The sample solution includes two projects. One is a Windows Control Library project named MyCompanyControls. The second is a Windows Application project named CustomDataControls.

The control library defines the PhoneBox control. The control simply inherits from MaskedTextBox control and sets the Mask property to a Phone Number with Area Code. The library project also contains an embedded resource, PhoneBox.bmp, to represent the icon in the ToolBox and Data Sources window.

The PhoneBox control is available in the CustomDataControls project. By selecting Rebuild from the project's shortcut menu, the PhoneBox will appear in the Toolbox in a new section named MyCompanyControls. You need to have Form1 opened in the designer in order to see the ToolBox items.

The Data Sources window is used to add the PhoneBox to the list of controls for String. In the Data Sources window, select the HomePhone column under the Employee table. Select the drop-down and choose Customize. This opens the dialog box for customizing the list of controls for given types. This list is populated with the list of controls currently in the Visual Studio ToolBox that implement the DefaultBindingPropertyAttribute. The PhoneBox control inherits from MaskedTextBox, which supports the DefaultBindingPropertyAttribute. Select String under Data Type and find the PhoneBox control in the list. The check by the PhoneBox control indicates to Visual Studio that the PhoneBox control is one of the available controls for any object that has a string property.

See Also

© 2016 Microsoft