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

  • Thread starter Thread starter Jim H
  • Start date Start date
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
 
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."
 
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."
 
Back
Top