Me
.DataGrid2.DataSource
=
abc
Me .DataGrid2.TableStyles.Add(gettablestyle(abc))
Private Function gettablestyle( ByVal table As DataTable) As DataGridTableStyle
Dim style As New DataGridTableStyle
style.MappingName = table.TableName
style.RowHeaderWidth = 15
style.AllowSorting = False
Dim i As Integer
For i = 0 To table.Columns.Count - 1
Dim c1 As New DataGridTextBoxColumn
c1.MappingName = table.Columns(i).ColumnName
' c1.Width = 130
c1.NullText = ""
' If i = 1 Or i = 2 Then '注意:就是这里来设置日期字段只显示日期。
c1.Format = " yyyy-MM-dd hh:mm:ss "
' End If
style.GridColumnStyles.Add(c1)
Next
Return style
End Function
Me .DataGrid2.TableStyles.Add(gettablestyle(abc))
Private Function gettablestyle( ByVal table As DataTable) As DataGridTableStyle
Dim style As New DataGridTableStyle
style.MappingName = table.TableName
style.RowHeaderWidth = 15
style.AllowSorting = False
Dim i As Integer
For i = 0 To table.Columns.Count - 1
Dim c1 As New DataGridTextBoxColumn
c1.MappingName = table.Columns(i).ColumnName
' c1.Width = 130
c1.NullText = ""
' If i = 1 Or i = 2 Then '注意:就是这里来设置日期字段只显示日期。
c1.Format = " yyyy-MM-dd hh:mm:ss "
' End If
style.GridColumnStyles.Add(c1)
Next
Return style
End Function