如何更改datagridview列日期格式? [英] how to change datagridview column date format?

查看:350
本文介绍了如何更改datagridview列日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在datagridview的日期栏中将日期格式从(mm/dd/yy)格式更改为(yy/mm/dd).可以在控制面板中更改每个区域的设置计算机,但我想以编程方式执行此操作,这意味着每当用户打开表单时,都将自动更改,谢谢.

How can I change date format from us format(mm/dd/yy)to(yy/mm/dd)in a date column from a datagridview.It''s possible to change settings in controlpanel>regional settings for each computer,but i want do that programmatically,i meant that whenever the user opens form,change automatically,thanks.

推荐答案

您应更改datagridview日期列默认单元格样式
You should change your datagridview date column Default cell style
datagridview .Columns[0].DefaultCellStyle.Format = "yy/mm/dd";


尝试以下方法:

DateTime d = DateTime.parse("01/25/2011");
d. ToString("yy/MM/dd");
Try Below:

DateTime d=DateTime.parse("01/25/2011");
d. ToString("yy/MM/dd");


您无法更改列的日期格式".

您可以做的是处理 OnCellFormatting [
如果您点击上面的链接,该页面上的代码将显示如何设置日期格式.
You cannot change the ''date format'' of the column.

What you can do is handle the OnCellFormatting[^] event of your DataGridView.

What this event does is allow you to take the actual value contained by a cell and change what actually gets displayed. So if the value of a cell is 10 you can actually display "bananas", without breaking your application.

If you follow the link above, the code on that page shows how to format dates.


这篇关于如何更改datagridview列日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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