DataGrid with DateTime

  • Thread starter Thread starter Ram Baruch
  • Start date Start date
R

Ram Baruch

Hi,
I have encountered the problem:
1. I have a sql server with a table in it.
2. One of the column's type in the table is datatime.
2. I have a form taht contains a datagrid control.
3. I attached the datagrid to the table in the DB.

One of the cells in the table contains the following data (datetime):
11/8/2004 4:14:37 PM
(I can see that if I open the DB through the server explorer in visual
studio).
When I run my application, and the DB is attached to the grid, the cell
contains:
11/8/2004
(thats what I see in the grid when I run the application- the time is
missing).

Is there something I forgot to do?
Do I have to configure something?
Help will be appreciated,
Regards,
Ram.
 
Hi Ram,

Based on my understanding, you want to display customized string
representation for datetime type column in datatable.

Default, if we do not specify any format string for the datagrid, it will
call each column's ToString() method to get the string representation of
that datacolumn. So you will get only the year, month and date
representation.

If you wanted to display customized string for the datetime type, we may
explicit set Format string for that column. This can be achieved through
adding a DataGridTableStyle with DataGridTextBoxColumn into the DataGrid's
TableStyles property. Just set DataGridTextBoxColumn's MappingName to that
datetime type column and set customized Format string for
DataGridTextBoxColumn.Format property.

For example, to display "11/8/2004 4:14:37 PM" string for datetime column,
we may use the format string below:
MM/dd/yyyy hh:mm:ss tt

It works well on my machine.

For the details reference about the customize format string of datetime,
please refer to:
"Custom DateTime Format Strings"
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcustomdatetimeform
atstrings.asp

For example, please refer to:
"Custom DateTime Format Strings Output Examples"
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcustomdatetimeform
atstringsoutputexamples.asp
===============================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Yes, this is the "Standard DateTime Format Strings" which is another option
for Ram, and the "Custom DateTime Format Strings" will give Ram some other
more customized options. Both for Sam's information.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top