You can just use an TextBox cell with this code:
//the initialization
GridStyleInfo style = this.gridControl1[2,2];
style.CellValueType = typeof(DateTime);
style.Format = "hh:mm tt";
style.CellValue = DateTime.Now;
//handle CurrentCellValidating to enforce teh format to your needs.
private void gridControl1_CurrentCellValidating(object sender, System.ComponentModel.CancelEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
GridStyleInfo style = this.gridControl1[cc.RowIndex, cc.ColIndex];
if(style.CellValueType == typeof(DateTime) && style.Format.Length > 0)
{
string[] validFormats = new string[]{style.Format, "h:mm tt", "h:m tt", "hh:m tt"};
string s = cc.Renderer.ControlText;
try
{
DateTime dt = DateTime.ParseExact(s, validFormats, null,
DateTimeStyles.AllowInnerWhite|DateTimeStyles.AllowLeadingWhite
|DateTimeStyles.AllowTrailingWhite|DateTimeStyles.AllowWhiteSpaces);
string s1 = dt.ToString(style.Format);
if(s1 != s)
{
cc.Renderer.Control.Text = s1;
}
}
catch
{
cc.ErrorMessage = "Invalid Time";
e.Cancel = true;
}
}
}
In 1.6, there is actually a Control celltype you can try to use to put a DateTimePicker in a cell. Below is some code. But it really is only useful for a static type control that does not change sizes an donly lives in a single cell. If you want a more versatile DateTimePicker in a cell, then you should use the technique illustrated in the Syncfusion\Essential Suite\Grid\Samples\CellTypes\CalendarCells sample in 1.6. It creates a MonthCalender cell that can be shared and sized among different grid cells bases on the Windows Forms DateCalendar control.
DateTimePicker dtp = new DateTimePicker();
dtp.AllowDrop = false;
dtp.ShowUpDown = true;
dtp.Format = DateTimePickerFormat.Custom;
dtp.CustomFormat = "hh:mm tt";
style = this.gridControl1[4,2];
style.CellValueType = typeof(DateTime);
style.Format = "hh:mm tt";
style.CellValue = DateTime.Now;
style.CellType = "Control";
style.Control = dtp;