whytheq
whytheq

Reputation: 35597

MonthCalendar to scroll to a different date when button is pressed

I have a winforms with a MonthCalendar control and a button. The button has the following code:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        myMonthCalendar.SelectionRange.Start = Convert.ToDateTime("01 jan 2012")
End Sub

What I was hoping would happen is that when I hit the button the calendar changes to the month of Jan 2012. When I hit the button no error occurs but it is still on the current month.

enter image description here

How do I get it to change to Jan 2012?

Upvotes: 1

Views: 1916

Answers (2)

maxedev
maxedev

Reputation: 941

This displays January 2012 on the button click and selects the 1st only:

myMonthCalendar.SetDate(Convert.ToDateTime("01 jan 2012"))

you can also use SetSelectionRange like phadaphunk mentioned, but note if you don't pass the same date for both parameters, multiple dates will be selected in the calendar up to the MaxSelectionCount

Upvotes: 1

phadaphunk
phadaphunk

Reputation: 13313

You should use the SetSelectionRange method.

 myMonthCalendar.SetSelectionRange(StartDate, EndDate)

Selection range is used to play with the selection or to get it's range. (Start and End) the SetSelectionRange() is used to set it.

Upvotes: 1

Related Questions