Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set the Month for MonthCalendar in program

Status
Not open for further replies.

TerDavis

Technical User
Sep 18, 2002
36
US
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 believe you just set the Date or Value property. I don't remember which but:

MonthCalendar myCal = new MonthCalendar();

myCal.Date = new DateTime(01, 01, 2005);
 
The MonthCalendar control for the windows form does not have a Date property ?

So, i used the following :

this.monthCalendar1.TodayDate = new DateTime(01, 01, 2005);

but the monthcalendar did not switch to January ??
 
The highlighted date (and therefore the month) in the MonthCalendar control is determined by the

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.


[vampire][bat]
 

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
 
i must be missing something..
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

 
Code:
  Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged

    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.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top