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.
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 Customizing Development Settings in Visual Studio.
To bind a control and format the displayed data
Connect to a data source.
For more information, see Connecting to a Data Source.
In the form, select the control, and then open the Properties window.
Expand the (DataBindings) property, and then in the (Advanced) box, click the ellipsis button () to display the Formatting and Advanced Binding dialog box, which has a complete list of properties for that control.
Select the property you want to bind, and then click the Binding arrow.
A list of available data sources is displayed.
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.
Click the name of an element to bind to.
In the Format type box, click 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.
Click OK to close the Formatting and Advanced Binding dialog box and return to the Properties window.