×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to set the Month for MonthCalendar in program

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.

RE: How to set the Month for MonthCalendar in program

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);

RE: How to set the Month for MonthCalendar in program

(OP)
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 ??

RE: How to set the Month for MonthCalendar in program

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.

RE: How to set the Month for MonthCalendar in program

(OP)

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

It does when I use the code I posted.

RE: How to set the Month for MonthCalendar in program

(OP)
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

RE: How to set the Month for MonthCalendar in program

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close