在DevExpress gridview vb.net中以编程方式格式化日期字符串

时间:2015-05-22 18:45:14

标签: vb.net gridview devexpress

我在DevExpress的网格视图中显示的日期是这样的:20071031(YYYYMMDD *),我希望它在gridview中显示为2007/10/31。

*数据从sql server表导入为Varchar。

我已经尝试了以下但是它没有做任何事情,日期仍然显示为YYYMMDD。

gridview.Columns("CloseDate").DisplayFormat.FormatType = FormatType.DateTime
gridview.Columns("CloseDate").DisplayFormat.FormatString = "d"

我也知道以下内容可以将字符串转换为所需的日期格式(但我无法将其应用于我的情况)。

Dim strDate As String = DateTime.ParseExact("20071117", "yyyyMMdd", Nothing).ToString("MM\/dd\/yyyy")

2 个答案:

答案 0 :(得分:0)

DevExpress支持团队为我提供了以下解决方案:

Private Sub gridview_CustomColumnDisplayText(sender As Object, e As DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs) Handles gridview.CustomColumnDisplayText
       If e.Column.FieldName = "CloseDate" Then
           Dim strDate As String = DateTime.ParseExact(e.Value, "yyyyMMdd", Nothing).ToString("MM\/dd\/yyyy")
           e.DisplayText = strDate
       End If
End Sub

答案 1 :(得分:0)

我不明白为什么你不能使用ParseExact,但也许你可以使用它:

    Dim D$ = "20150522"
    Dim mData =  D.substring(4,2) & "/" & D.substring(6) & "/" & D.substring(0,4)
相关问题