Question : format date in text box control

I have a form with an underlying dataset (from a sql server db) that is bound to various textboxes.  A couple of the fields in the dataset contain dates.  Is there a way to format the dates in the text boxes.

Currently they display as ‘06/10/2003 00:00:00’

I need them to display as 06/10/2003.

Is this possible?

Answer : format date in text box control

use the Binding.Format Event

search "Binding.Format Event" in msdn for further details

from msdn:
Remarks
The Format event occurs both when data is pushed from the data source into the control, and when the data is pulled from the control into the data source. When the data is pushed from the data source into the control, the Binding will use the Format event to put the formatted data into the control. When the data is pushed from the control into the data source, the Binding will first parse the data using the Parse event, then format the data and push the it into the control.

The Format and Parse events allow you to create custom formats for displaying data. For example, if the data in a table is of type Decimal, you can display the data in the local currency format by setting the Value property of the ConvertEventArgs object to the formatted value in the Format event. You must consequently unformat the displayed value in the Parse event.

The Format event occurs whenever the Current value of the BindingManagerBase changes, which includes:

The first time the property is bound.
Any time the Position changes.
Whenever the data-bound list is sorted or filtered, which is accomplished when a DataView supplies the list.
The Format event also occurs after the Parse event. For example, when a control loses focus, its contents are parsed. Immediately afterwards, as new data is pushed into the control, the Format event occurs allowing the new contents to be formatted.



the edge
Random Solutions  
 
programming4us programming4us