Spread for ASP.NET 10 Product Documentation > Developer's Guide > Customizing with Cell Types > Working with Editable Cell Types > Setting a Date-Time Cell |
You can use date-time cells to restrict users to entering dates or times and to display data as date or time values.
You determine the format of the date and time to display by specifying the DateTimeFormatInfo object. For a complete list of date and time formats, refer to the DateTimeCellType class.
To create a time cell to display only hours and minutes, set the format string to "hh:mm".
If a date time cell displays dates and times in long date and time format, and the current date and time is "10/29/2002 11:10:01", the Text property returns "Tuesday, October 29, 2002 11:10:01 AM" as the formatted value of the cell. The Value property returns the date-time object.
You can specify an edit mode format with the EditMode property and the DateTimeCellType.EditModeSettings class.
For details on the properties and methods for this cell type, refer to the DateTimeCellType class.
Display the date in the format of Tuesday, March 04 (day of week, month and number of day) in the second row, second column cell. If the user inputs an invalid entry, display a note, as shown in the figure below.
C# |
Copy Code
|
---|---|
FarPoint.Web.Spread.DateTimeCellType datecell = new FarPoint.Web.Spread.DateTimeCellType(); datecell.ErrorMessage = "Need a date!!!"; datecell.FormatString = "dddd, MMMM d"; FpSpread1.ActiveSheetView.Columns[1].Width = 175; FpSpread1.ActiveSheetView.Cells[1, 1].CellType = datecell; |
VB |
Copy Code
|
---|---|
Dim datecell As New FarPoint.Web.Spread.DateTimeCellType() datecell.ErrorMessage = "Need a date!!!" datecell.FormatString = "dddd, MMMM d" FpSpread1.ActiveSheetView.Columns(1).Width = 175 FpSpread1.ActiveSheetView.Cells(1, 1).CellType = datecell |