Default Date Editor | Date Editor Without Calendar | Date Editor with Spin Button |
---|---|---|
Use the code below to create a Date editor in a WinForms FlexGrid column.
As mentioned earlier, in FlexGrid, a DateTime type cell automatically displays a dropdown calendar to receive the input from user. However, in order to get a date input from user without displaying a calendar, you can set a mask using the EditMask property and then validate the input value using the ValidateEdit event.
Following code demonstrates how to create a Date editor without calendar in WinForms FlexGrid
For more information about cell masks and validation, see topics Mask and Validation respectively. Another way of hiding the calendar is to get user input using the spin buttons.Below code shows how to create Date editor with spin button.
To display spin buttons in a Date editor, use the SetupEditor event to convert the editor into DateTimePicker and set its ShowUpDown property to true.
To set the format in a Date type column, you need to set the Format property of the Column object.
Following table lists the pre-defined formats:
Format | Value | Example |
---|---|---|
Short Date | d |
11/19/2003 |
Long Date | D | Friday, November 19, 2003 |
Short Time | t | 12:15 AM |
Long Time | T | 12:15:30 AM |
You can also create a custom format using the various custom format specifiers supported in the .Net framework. For details, see Custom date and time format strings on Microsoft website.
Use the following code to create a custom date format in WinForms FlexGrid column.
Although abovementioned formats are the most commonly used date formats, but there are cultures which prefer using their specific calendar and date formats in some cases such as Japan. You can display those specific calendars and date formats by using OwnerDrawCell event of the C1FlexGrid class and the System.Globalization namespace. The namespace provides various classes to define culture related information including calendars and date formats. For instance, to display Japanese calendar and Japanese date format, you can leverage the System.Globalization.JapaneseCalendar class. Similarly, you can also display other calendars such as Gregorian, Hebrew, Hijri, and Korean.
Set the country specific date format in WinForms FlexGrid using the code below.
To set a range of valid values, you can use the DateTimePicker control as editor and set its MinDate and MaxDate property.
Use the code below to set a range of valid dates in WinForms FlexGrid.