How to set the Month for MonthCalendar in program
How to set the Month for MonthCalendar in program
(OP)
Hi,
I am using the MonthCalendar and i would like to set the
month within the program.
So that when a person clicks on a Jan or Feb link, the monthCalendar control will display the selected month.
How do i do this ? in the .ASP .NET control there is a VisualDate property but no such thing for the MonthCalendar.
I am using the MonthCalendar and i would like to set the
month within the program.
So that when a person clicks on a Jan or Feb link, the monthCalendar control will display the selected month.
How do i do this ? in the .ASP .NET control there is a VisualDate property but no such thing for the MonthCalendar.
RE: How to set the Month for MonthCalendar in program
MonthCalendar myCal = new MonthCalendar();
myCal.Date = new DateTime(01, 01, 2005);
RE: How to set the Month for MonthCalendar in program
So, i used the following :
this.monthCalendar1.TodayDate = new DateTime(01, 01, 2005);
but the monthcalendar did not switch to January ??
RE: How to set the Month for MonthCalendar in program
MonthCalendar.SelectionRange property
as in MonthCalendar1.SelectionRange.Start
and MonthCalendar1.SelectionRange.End
but Microsoft has kindly supplied these two properties as seperately as:
MonthCalendar.SelectionStart and MonthCalendar.SelectionEnd
They can be set to the same date or to different dates (the MaxSelectionCount property determines the number of days that will be highlighted - default is 7)
MonthCalendar1.SelectionStart = new DateTime(01, 01, 2005);
MonthCalendar1.SelectionEnd = new DateTime(01, 01, 2005);
Hope this helps.
RE: How to set the Month for MonthCalendar in program
Hello,
I tried the setting of the SelectionStart and SelectionEnd,
but still the calendar do not refresh itself to show January.
????? You would think that this would work, but i must be missing something ???
Once i set the selection range, how do i force the calendar to change ....
thanks
-ter
RE: How to set the Month for MonthCalendar in program
RE: How to set the Month for MonthCalendar in program
here is my code...
if (strCmd == "January")
{
lnkJan.BorderStyle = BorderStyle.FixedSingle;
monthCalendar1.SelectionStart = new DateTime(01, 01,2005);
monthCalendar1.SelectionEnd = new DateTime(01, 01, 2005);
}
I also tried
monthCalendar.SelectionRange.Start
monthCalendar.SelectionRange.End...
and added a
monthCalendar1.Refresh();
the calendar currently displays the month of october...
but when i click on January, october is still displayed.
When i physically click on the previous, the day 01 is highlighted, so that works...but i need it to switch to display the month of Jan.
Can you send me your code ???
Thanks,
-ter
RE: How to set the Month for MonthCalendar in program
CODE
MonthCalendar1.SelectionStart = DateTimePicker1.Value
MonthCalendar1.SelectionEnd = DateTimePicker1.Value
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MonthCalendar1.SelectionStart = New Date(2005, 1, 31)
MonthCalendar1.SelectionEnd = New Date(2005, 1, 31)
End Sub
Its VB.Net but it shouldn't make any difference.
As you can see, I use two different methods to change the MonthCalendar, a DateTimerPicker's ValueChanged event and a Button's Click event.
The DTP is used to change the MonthCalendar to the same date as the user selects in the DTP, whereas the Button changes the MonthCalendar to a specific date.
Hope this helps.