Spread ASP.NET 17
Spread for ASP.NET 17 Product Documentation / Developer's Guide / Customizing with Cell Types / Working with Editable Cell Types / Setting a Date-Time Cell
In This Topic
    Setting a Date-Time Cell
    In This Topic

    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.

    Using Code

    1. Define the date-time cell type by creating an instance of the DateTimeCellType class.
    2. Specify the message to display if invalid.
    3. Specify the format of the date to display using the FormatString property.
    4. Assign the date-time cell type to a cell.

    Example

    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.

    Date Time Cell Type with Message

    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 
    

    Using the Spread Designer

    1. In the work area, select the cell or cells for which you want to set the cell type.
    2. Select the Home menu.
    3. Select the SetCellType icon under the CellType section.
    4. Select the cell type and any other cell properties.
    5. Select OK to close the dialog.
    6. Click Apply and Exit to close the Spread Designer.
    See Also