//Create CustomCellModel
class DateTimeExt1Model : GridDropDownMonthCalendarCellModel
{
public DateTimeExt1Model(GridModel grid)
: base(grid)
{
}
public override bool ApplyFormattedText(GridStyleInfo style, string text, int textInfo)
{
string month;
string year;
DateTime isDate;
//To set the month and year of previous value.
if (style.Text != string.Empty && DateTime.TryParse(style.CellValue.ToString(),out isDate) && text.Length<=2)
{
DateTime time = (DateTime)style.CellValue;
month = time.Month.ToString();
year = time.Year.ToString();
month += "-" + text + "-" + year;
}
//To set the current month and year
else if (text.Length <= 2)
{
month = DateTime.Now.Month.ToString();
year = DateTime.Now.Year.ToString();
month += "-" + text + "-" + year;
}
else
month = text;
return base.ApplyFormattedText(style, month, textInfo);
}
public override GridCellRendererBase CreateRenderer(GridControlBase control)
{
return new DateTimeExt1Renderer(control, this);
}
}
//Adding CustomCellModel
this.gridGroupingControl1.TableModel.CellModels.Add("DateTimeExt", new DateTimeExtModel(this.gridGroupingControl1.TableModel));
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.CellType = "DateTimeExt";
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.CellValueType = typeof(DateTime);
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.Format = "dd/MM/yyyy";
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.ShowButtons = GridShowButtons.Hide; |
public override bool ApplyFormattedText(GridStyleInfo style, string text, int textInfo)
{
string month;
string year;
DateTime isDate;
//To set the month and year of previous value.
if (style.Text != string.Empty && DateTime.TryParse(style.CellValue.ToString(),out isDate) && text.Length<=2)
{
DateTime time = (DateTime)style.CellValue;
month = time.Month.ToString();
year = time.Year.ToString();
month += "-" + text + "-" + year;
}
//To set the current month and year
else if (text.Length <= 2)
{
month = DateTime.Now.Month.ToString();
year = DateTime.Now.Year.ToString();
month += "-" + text + "-" + year;
}
else
month = text;
return base.ApplyFormattedText(style, month, textInfo);
} |