当datagridview单元正好在午夜时,如何显示完整的DateTime值? [英] How to show the complete DateTime value in a Datagridview cell when it is exactly midnight?

查看:116
本文介绍了当datagridview单元正好在午夜时,如何显示完整的DateTime值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGridView,其中包含一个具有DateTime值的列,如下所示:





问题出在所选行:实际上具有值10/07/2015 12:00:00 am,但在datagridview中只显示10/07/2015 。
下一行的值为10/07/2015 12:00:26 am。仅当DateTime值的小时正好是午夜时,才会出现此问题。
当我使用以下代码将该值传递给一个textBox(左边)时,DateTime值被正确显示(DateTime值在索引为2的列中):

  text1.Text = dgView.SelectedRows [0] .Cells [2] .Value.ToString(); 

如何让我的DataGridView显示完整的DateTime值?
我不想设置 DefaultCellStyle.Format 值,因为我想显示DateTimes的格式为OS区域设置(在我的例子中是es-pe)。



我的目标是为.net 3.5编译为x86。

解决方案

您可以指定 DefaultCellStyle.Format ,但使用标准格式将适当地本地化:

  DefaultCellStyle.Format =g; //一般日期,短时间模式

我不知道这将格式化为午夜完全,但值得一试。


I have a DataGridView with a column that holds DateTime values like this:

The problem is in the selected row: it actually has the value "10/07/2015 12:00:00 am" but in the datagridview it is shown only "10/07/2015". The next row has the value of "10/07/2015 12:00:26 am". This problem happens only when the hour of the DateTime values is exactly midnight. When I pass that value to a textBox (to the left) with the following code, DateTime value is shown correctly (DateTime values are in the column with index 2):

text1.Text = dgView.SelectedRows[0].Cells[2].Value.ToString();

How can I make my DataGridView to show the complete DateTime values? I do not want to set the DefaultCellStyle.Format value because I want to show the DateTimes in the format of the OS regional settings (in my case is es-pe).

I'm targeting .Net 3.5 compiled for x86.

解决方案

You could specify the DefaultCellStyle.Format, but use a "standard format" which will localize appropriately:

DefaultCellStyle.Format = "g"; // General date, short time pattern

I don't know that that will format midnight "fully", but it's worth a try.

这篇关于当datagridview单元正好在午夜时,如何显示完整的DateTime值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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