How do I display time with date in a DataGrid from a DateTime data column?

J

Jim H

I have a DataGrid where the DataSource is a DataTable that has a DateTime
column. Right now it only shows the Date, I want the date and time down to
the seconds or better. How do I set the DataGrid to display the DateTime
value in the format I want.

DateTime.ToString("MM/dd/yyy hh:mm:ss:fff")

Thanks,
jim
 
K

Kevin Yu [MSFT]

Hi Jim,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to display the Date and Time
information in a grid cell. If there is any misunderstanding, please feel
free to let me know.

As far as I know, we can use datagridcolumnstyle mapping to achieve this. A
data grid has a property named TableStyles. In the styles collection, there
are mappings for the columns. You can set DataGridTextBoxColumn.Format to
"MM/dd/yyyy hh:mm:ss:fff". This will do the trick. Thanks!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

You're welcome, Jim.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top