Hi,
I have a grid bound to a datatable. The datatable is linked to a SQL table. One of the columns is smalldatetime.
How do i get the grid to display hours and minutes after the date? The data is in the table.
I''ve been trying the following to no evail There is no error message, however it does not achieve the desired result.
Thanks in advance,
Damien
Me.grdStatusHistory.DataSource = dtResult
Me.grdStatusHistory.Binder.SetDataBinding(dtResult, "")
Me.grdStatusHistory.Model.ColStyles(Me.grdStatusHistory.Binder.NameToColIndex("dDateChanges")).Format = "dd-MMM-yyyy hh:mm"
Me.grdStatusHistory.Refresh()
AD
Administrator
Syncfusion Team
August 5, 2004 05:22 AM UTC
The style.Format does not work unless you also set the style.CellValueType to reflect the proper System.Type. So try
Me.grdStatusHistory.Model.ColStyles(Me.grdStatusHistory.Binder.NameToColIndex("dDateChanges")).CellValueType = GetType(DateTime)
DS
Damien Sawyer
August 9, 2004 11:23 PM UTC
Thanks for that Clay,
Unfortunately it didn''t work. My code now looks like ....
Notice that I did the formatting twice, with both "Date Changed" and "dDateChanged"... just to check.
Any ideas?
Thanks,
DS
Dim sSQL As String = ""
Dim dtResult As New DataTable
sSQL += "SELECT "
sSQL += "iID [ID],"
sSQL += "OrderNumber [Order Number],"
sSQL += "iItemID [Item ID],"
sSQL += "SecondID [Second ID],"
sSQL += "iStatusOld [Old Status],"
sSQL += "iStatusNew [New Status],"
sSQL += "dDateChanges [Date Changed] "
sSQL += " from dbo.tblOrderStatusChangeLog "
sSQL += "WHERE OrderNumber = " & Me._iOrderNumber.ToString & " "
sSQL += "AND SecondID = ''" & Me._cLITM.Trim & "'' "
sSQL += "order by dDateChanges"
Dim daLogs As SqlDataAdapter = New SqlDataAdapter(sSQL, Me._oRoot.oSQLConn)
daLogs.Fill(dtResult)
Me.grdStatusHistory.DataSource = dtResult
Me.grdStatusHistory.Binder.SetDataBinding(dtResult, "")
Me.grdStatusHistory.Model.ColStyles(Me.grdStatusHistory.Binder.NameToColIndex("dDateChanges")).CellValueType = GetType(DateTime)
Me.grdStatusHistory.Model.ColStyles(Me.grdStatusHistory.Binder.NameToColIndex("dDateChanges")).Format = "dd-MMM-yyyy hh:mm"
Me.grdStatusHistory.Model.ColStyles(Me.grdStatusHistory.Binder.NameToColIndex("Date Changed")).CellValueType = GetType(DateTime)
Me.grdStatusHistory.Model.ColStyles(Me.grdStatusHistory.Binder.NameToColIndex("Date Changed")).Format = "dd-MMM-yyyy hh:mm"
Me.grdStatusHistory.Refresh()
AD
Administrator
Syncfusion Team
August 10, 2004 05:22 AM UTC
I am sorry, it did not register with me that you were using ColStyles.
If grdStatusHistory is a GridDataBoundGrid, then you will need to set the style for the column using the GridBoundColumn object for the column. So, if you have not explicitly added GridBoundColumns, you would use code like
grdStatusHistory.Binder.InternalColumns("dDateChanges").StyleInfo.CellValueType = GetType(DateTime)
Me.grdStatusHistory.Binder.InternalColumns("dDateChanges").StyleInfo.Format = "dd-MMM-yyyy hh:mm"
If you have explicitly added GridBoundColumns, then you use the grdStatusHistory.GridBoundColumns collection set the styles on the columns.