【问题标题】:How to set the date format of dd-MMM-yy in DataGridView at design time in vb.net?如何在 vb.net 设计时在 DataGridView 中设置 dd-MMM-yy 的日期格式?
【发布时间】:2016-01-06 16:57:56
【问题描述】:

我正在开发 vb.net windows 应用程序。

我使用网格视图来显示数据。

我想在DataGridView 中使用dd-MMM-yy 格式。

例如,我想将时间显示为 01-Jan-16

但我在 VS 2012 IDE 中看不到这种格式。

这是它的图像......

我可以使用自定义格式吗?它的格式是什么?

【问题讨论】:

    标签: vb.net winforms datagridview


    【解决方案1】:

    您可以在设计时或运行时使用DataGridViewCellStyle.Format 属性将格式设置为dd-MMM-yy。然后它将日期显示为06-Jan-16

    转到Columns 属性,然后打开Edit Columns 窗口。在Appearance 类别下,编辑DefaultCellStyle,打开CellmStyle Builder 窗口并在Behavior 类别下输入自定义Format

    您也可以点击... 并打开Format String Dialog 并在预定义格式和自定义格式之间进行选择,然后在此处输入自定义格式:

    或者使用代码你可以写这个代码:

    Dim DataGridViewCellStyle1 = New DataGridViewCellStyle()
    DataGridViewCellStyle1.Format = "dd-MMM-yy"
    Me.Column1.DefaultCellStyle = dataGridViewCellStyle1
    

    有关可与Format 属性一起使用的支持格式的更多信息,请参阅Formatting Types in the .NET Framework

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-30
      • 1970-01-01
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多