We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Min and Max date for MonthCalendar cell

Thread ID:





18872 Sep 10,2004 05:05 PM Sep 14,2004 12:39 PM Windows Forms 7
Tags: GridControl
Asked On September 10, 2004 05:05 PM

I''m using some MonthCalendar controls in a GridControl. grid1[4,3].CellType = "MonthCalendar"; grid1[4,3].CellValue = DateTime.Now; grid1[4,3].Format = "MM/dd/yyyy"; Is there a way to set the min/max dates allowable for the month calendar drop down? Thanks!

Administrator [Syncfusion]
Replied On September 10, 2004 05:42 PM

You can use CurrentCellShowingDropDown and set the values there dynamically. You do have to hunt down the calendar control as it is not exposed as a public member of the renderer class.
private void gridControl1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	GridDropDownMonthCalendarCellRenderer cr = cc.Renderer as GridDropDownMonthCalendarCellRenderer;
	if(cr != null)
		MonthCalendar cal = null;
		foreach(Control c in cr.DropDownContainer.Controls)
			if(c is MonthCalendar)
				cal = c as MonthCalendar;
		if(cal != null)
			cal.MaxDate = DateTime.Now.AddDays(100);
			cal.MinDate = DateTime.Now.AddDays(-100);

Replied On September 13, 2004 06:17 PM

Is there any other way to get at the calendar control before it''s dropped down by the user? The text field portion of the control needs to be in a certain format (MMM dd, yyyy) and displayed like that with default values when the form loads - before the user is going to start clicking on the controls. Thanks.

Administrator [Syncfusion]
Replied On September 14, 2004 01:32 AM

To use a custom date, you can use the style.Format property to set the format. GridStyleInfo style = this.gridControl1[1,2]; style.CellType = "MonthCalendar"; style.CellValueType = typeof(DateTime); style.Format = "dd/MM/yy HH.mm.ss"; style.CellValue = DateTime.Now; But if you specify the format that is not consistent with the regional settings for dates, this will cause the grid to throw an exception as you try to drop the calendar. This is not a problem if you are not allowing editing, or if the format is consistent with the regional setting. But if you do run into the problem, one way to work around it is to derive the cell control and set the value into the calendar dropdown taking into account the format provided in the style. Here is a sample. This sample has both the custom celltype that handles the format, as well as several grid events that can also do the same thing. To see the grid events work, add this code to set one of the cells to use the standard MonthCalendar. //uses events to set a format style = this.gridControl1[5,2]; style.CellType = "MonthCalendar"; style.CellValueType = typeof(DateTime); style.Format = "MM/dd/yy HH.mm.ss"; style.BackColor = Color.LightGoldenrodYellow; style.CellValue = DateTime.Now;

Replied On September 14, 2004 11:26 AM

Thanks Clay. I''m trying to run the sample you provided, and get build errors around CalendarControlSize GridCapture HScrollPixel ...etc... I suspect you''re using a newer grid vesion. I''m on I''ll have to look into deriving the cell control to handle different culture settings. One more question :) Is there a way to make the edit portion of the month calendar control read-only? I don''t want to allow users to type in the date, only select it from the drop-down. Thanks.

Administrator [Syncfusion]
Replied On September 14, 2004 11:52 AM

Try just commenting out anything that causes a syntax error. Try handling the CurrentCellStartEditing event. In your handler, set e.Cancel = true if grid.CurrentCell.RowIndex/ColIndex point to a cell on which you do not want to allow editing.

Replied On September 14, 2004 12:05 PM

Thanks - setting e.Cancel = true works, prevents editing in the text portion of the calendar control, BUT has the following side effect: When I drop down the calendar control, and choose a date, that date is not placed into the edit box.

Administrator [Syncfusion]
Replied On September 14, 2004 12:39 PM

Here is a sample that does this using CurrentCellKeyPress event.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.