Ram Kumar K

Hi,
Can anyone please let me know how to set the DisplayRange of the MonthCalendar control of .NET 2.0.
There is a method MonthCalendar.GetDisplayRange(bool) but am not able to find a way to set the DisplayRange.


Best Regards,


Re: Windows Forms General MonthCalendar control set DisplayRange

BabyFace Jay

Hi, I found that a selectionRange is returned back, maybe you could change the value of its Start and End properties and see if what you wanted to achieve is achieved

Code Snippet

SelectionRange sr = this.monthCalendar1.GetDisplayRange(true);

sr.Start = XXX;

sr.End = YYY;





Re: Windows Forms General MonthCalendar control set DisplayRange

Ram Kumar Karnataka

Hello Jay,
Thanks for the reply. But i have already tried to set Start and End dates of the object returned by GetDisplayRange() but with no success.


Best Regards,




Re: Windows Forms General MonthCalendar control set DisplayRange

nobugz

That's not how MonthCalendar works. It can only display a single month. What DisplayRange you get purely depends on the day of the week the first and last day of the month happen to fall on.





Re: Windows Forms General MonthCalendar control set DisplayRange

Ram Kumar Karnataka

Hi,
I am setting the CalendarDimensions property to 3,1 to display 3 months calendar.
The exact problem is, I want to have a combo box to select the year. Based on the selected year, the month calendar shows the 3 months which it is currently showing but of the year's selected. Say for example, if the MonthCalendar shows the SEP, OCT and NOV months of the year 2007. If the user selects 2011 from the comboxbox, i have to show SEP, OCT, NOV of 2011 by keeping the selected date as same before and after changing.

Please let me know if any work around is there to do this.


Best Regards,




Re: Windows Forms General MonthCalendar control set DisplayRange

nobugz

This worked well, just a tiny bit of flicker:

public partial class Form1 : Form {
public Form1() {
InitializeComponent();
for (int ix = 0; ix < 200; ++ix) comboBox1.Items.Add((ix + 1990).ToString());
comboBox1.SelectedIndex = DateTime.Now.Year - 1990;
comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
DateTime dt = monthCalendar1.SelectionStart;
dt = new DateTime(int.Parse(comboBox1.Text), dt.Month, dt.Day);
monthCalendar1.SelectionStart = dt;
monthCalendar1.SelectionEnd = dt.AddMonths(monthCalendar1.CalendarDimensions.Width);
monthCalendar1.SelectionEnd = dt;
}
}





Re: Windows Forms General MonthCalendar control set DisplayRange

Ram Kumar Karnataka

Hi,
This is what exactly i needed.
Thanks.


Regards,