如何在Windows应用程序中的datagridview中格式化日期时间 [英] How to format date time in datagridview in windows application

查看:98
本文介绍了如何在Windows应用程序中的datagridview中格式化日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。希望你没事......

我正在构建一个Windows应用程序并面临一个问题。当我填充DataGridView时,Date格式显示我喜欢12/12/2017 12:00:00以及时间我想在这里做的是我想只显示DD / mm / yyyy格式的日期,除了时间我将要做些什么,请提出一些建议......谢谢提前



我尝试过的方法:



以下代码对我不起作用:



Hi Everyone Hope you are fine...
I am building a windows application and face a problem into it. when i populate the DataGridView the Date format show me like "12/12/2017 12:00:00" along with time what i want to do here is i want to display only date in "DD/mm/yyyy" format except time what i will have to do kindly post some suggestions... thankx in advance

What I have tried:

the following code do not work for me:

dataGrid.Columns[2].DefaultCellStyle.Format = "MM/dd/yyyy"

推荐答案

当我尝试使用dataGridView时,它工作正常,提供日期信息I加载到DGV数据源实际上是一个DateTime值:如果它是一个日期的字符串表示,那么它就无法用它做任何事情。



检查你的数据源:如果它是一个DB,请确保源列是DATE或DATETIME,并且在检索信息时不要使用CONVERT对其进行格式化。
When I try that with a dataGridView, it works fine, provided the date information I have loaded into the DGV data source is actually a DateTime value: if it's a string representation of a date, then it can't do anything with it.

Check your data source: if it's a DB, make sure that the source column is DATE or DATETIME and that you don't format it with a CONVERT when you retrieve the information.


这篇关于如何在Windows应用程序中的datagridview中格式化日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆