Format Date in Combo Box

Rogue 1

Member
Joined
Oct 5, 2006
Messages
12
Programming Experience
Beginner
Have combo box that is binded to a date field in an Access database. For the life of me I can not get rid of the time at the end.

I have the Data Type set to Date/Time in Access and the format is Short Date. All the dates are entered as mm/dd/yyyy. The value in the dataset is set to Date (not dateandtime). Also curious why this would not take care of it.

Thanks for any help in advance.
 
Access just suppresses that information when you choose "ShortDate", the numbers are still there. When loading the information into your ComboBox just format it how you want:

Try:

VB.NET:
Format(Now, "dd/MM/yyyy")

Where Now is the variable you've got your time stored in.
 
You can't be calling methods to format the date and then assigning the result if the ComboBox is bound to a data source.

When you get your data from the database the dates are returned as Date objects. ALL Date objects have the same internal format and the format you use to display them as strings is COMPLETELY unrelated to that. Whenever you you convert a Date object to a string to display it you have to specify the format or else the system default will be used. The ComboBox control has a FormatString property to which you assign a string that dictates how any numerical or date/time data will be displayed. This property will accept any valid standard or custom format string. To find out what constitutes a valid standard or custome format string you should go to MSDN and read the relevant help topics, to which I've provided links below. In your case the appropriate format string would be "d" for the standard short date format or "MM/dd/yyyy" for that specific format. Note that "d" is a better choice in geenral because it will use the current system's standard format. If you force the format to "MM/dd/yyyy" on a sytem where the user has set the date format to "dd/MM/yyyy", as I have here in Australia, then they will probably read the wrong date. It is always preferable to use the current system standard rather than enforcing your own system. If you do enforce your own system then you had better make very sure that the user is aware of this because they have a right to expect that your software will respect their choices.

http://msdn2.microsoft.com/en-us/library/fbxft59x.aspx
 
Thanks for the in-depth reply Jmc. I am pretty new to programming in general so this helps out alot. I used the link below and see several examples, however all of these code examples seem to print messages and not format a bound combo box.

I think my main problem is not understanding where code should be placed that deals directly with a control. Sorry for being such a newb. :(
 
I specifically said that you need to assign the format string to the ComboBox's FormatString property. There is no code. You set it in the Properties window at design time.
 
Doh!! It did not click when you said Property but I can not locate "FormatString property" in the properties box. That may explain why I did not understand your previous post.

I reviewed all the properties in the box and none of them seem to fit FormatString.

Sorry for understanding.
 
LOL. I figured out another method two seconds after that last post. I formatted the value in the Select statement using "d".

Thanks for the help.
 
OK, sorry, that's completely my fault. The FormatString property is new in .NET 2.0 and you're using VB.NET 2003, so of course you won't be able to find it. My humblest apologies.
 
Back
Top