Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

format date in text box control

Posted on 2003-11-17
5
Medium Priority
?
1,114 Views
Last Modified: 2012-05-04
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?
0
Comment
Question by:WingYip
5 Comments
 
LVL 1

Expert Comment

by:ob2
ID: 9763177
Easy Peasy

1) TextBox.Text = String.Format("{0:d}", Date)

Where d is always lowercase for short date and where date is the date from your dataset.
0
 
LVL 3

Accepted Solution

by:
the-edge earned 200 total points
ID: 9763226
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
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10268075
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: ob2 {http:#9763177} & the-edge {http:#9763248}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
 
LVL 1

Author Comment

by:WingYip
ID: 10280269
Have just tested the code.

the-edge gets the points

Thanks

Wing
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question