I have several places where I am selecting columns from SQL and loading them into a grid which are datatype "Time(0)" in SQL. I have attempted to format them using the following:
e.Layout.Bands(0).Columns("TimeIn").Format = "hh:mm:ss tt"
But to no avail. This works fine if I cast the columns in SQL as DateTime, but otherwise does not. Is there a different format string for Time datatypes?
Hi Nick,
Thank you for posting in our forums.
It doesn’t really matter what the type of the field is in your database. What actually matters is what the type of the field is in the grid’s data source. If it is of type DateTime the code that you are using will work. If it is of type string this code won’t work since setting a format of a string doesn’t do anything. If this is the case set the column’s Style to Time:
e.Layout.Bands(0).Columns("TimeIn").Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Time
Please let me know if you have any additional questions.
I have attempted to do this using both columnstyle.time and columnstyle.datetime, but to no avail:
e.Layout.Bands(0).Columns("TimeIn").Style = ColumnStyle.DateTime e.Layout.Bands(0).Columns("TimeIn").Format = "hh:mm:ss tt" e.Layout.Bands(0).Columns("TimeIn").Header.Appearance.TextHAlign = Infragistics.Win.HAlign.Center e.Layout.Bands(0).Columns("TimeIn").CellAppearance.TextHAlign = Infragistics.Win.HAlign.Center
This still formats incorrectly, not using the format string I have assigned. The above is called in InitializeLayout of the grid.
If you use the datatype Time from SQL server , then the grid is not working. If you cast the Time to DateTime in the select it will work. I just had the same problem.