How to: Create a Bound Control and Format the Displayed Data

With Windows Forms data binding, you can format the data displayed in a data-bound control by using the Formatting and Advanced Binding dialog box.

To bind a control and format the displayed data

  1. Connect to a data source. For more information, see Connecting to a Data Source.

  2. In Visual Studio, select the control on the form, and then open the Properties window.

  3. Expand the (DataBindings) property, and then in the (Advanced) box, click the ellipsis button (The Ellipsis button (...) in the Properties window of Visual Studio) to display the Formatting and Advanced Binding dialog box, which has a complete list of properties for that control.

  4. Select the property you want to bind, and then select the Binding arrow.

    A list of available data sources is displayed.

  5. Expand the data source you want to bind to until you find the single data element you want.

    For example, if you are binding to a column value in a dataset's table, expand the name of the dataset, and then expand the table name to display column names.

  6. Select the name of an element to bind to.

  7. In the Format type box, select the format you want to apply to the data displayed in the control.

    In every case, you can specify the value displayed in the control if the data source contains DBNull. Otherwise, the options vary slightly, depending on the format type you choose. The following table shows the format types and options.

    Format type Formatting option
    No Formatting No options.
    Numeric Specify number of decimal places by using Decimal places up-down control.
    Currency Specify number of decimal places by using Decimal places up-down control.
    Date Time Select how the date and time should be displayed by selecting one of the items in the Type selection box.
    Scientific Specify number of decimal places by using Decimal places up-down control.
    Custom Specify a custom format string using.

    For more information, see Formatting Types. Note: Custom format strings are not guaranteed to successfully round trip between the data source and bound control. Instead handle the Parse or Format event for the binding and apply custom formatting in the event-handling code.
  8. Select OK to close the Formatting and Advanced Binding dialog box and return to the Properties window.

See also