By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

Highlight entire week in MonthCalendar Control

P: n/a
Based on the date that the user selects, I'm trying to make the
MonthCalendar control highlight the entire week. In my case, the week
is from Monday - Sunday. I thought that using AddBoldedDate along
with selectionrange.start and .end would accomplish this, but it
doesn't.

Here is my code:

Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles
MonthCalendar1.DateChanged
Dim dateToday As Date = MonthCalendar1.SelectionRange.Start
Dim LastMonday As Date
Select Case dateToday.DayOfWeek
Case DayOfWeek.Monday
LastMonday = MonthCalendar1.SelectionRange.Start
Case DayOfWeek.Tuesday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-1)
Case DayOfWeek.Wednesday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-2)
Case DayOfWeek.Thursday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-3)
Case DayOfWeek.Friday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-4)
Case DayOfWeek.Saturday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-5)
Case DayOfWeek.Sunday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-6)
End Select

With MonthCalendar1
.SelectionRange.Start = LastMonday
.SelectionRange.End = LastMonday.AddDays(7)
for x = 0 to 6
.AddBoldedDate(LastMonday.AddDays(x))
next
End With
End Sub

Thanks,
Randy

Sep 24 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Any takers?

Sep 24 '07 #2

P: n/a
I was looking to solve the same problem when I found your post. This
works for me:

Private Sub dtPick1_DateSelected(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles
dtPick1.DateSelected
Dim i As Integer = CInt(dtPick1.SelectionStart.DayOfWeek)
Dim d As Date = dtPick1.SelectionStart
dtPick1.SelectionStart = d.AddDays(1 - i)
dtPick1.SelectionEnd = d.AddDays(7 - i)
End Sub

Note that I'm triggering off the DateSelected event, not DateChanged,
that way it doesn't re-trigger itself.
The seed values in the AddDays method make it Monday first day of
week. Otherewise use 0 and 6.
Enums always have an integer value behind, so you can avoid the Select
Case language.

Bob Graham

On Sep 23, 5:44 pm, Randy <spam.eastl...@gmail.comwrote:
Based on the date that the user selects, I'm trying to make the
MonthCalendar control highlight the entireweek. In my case, theweek
is from Monday - Sunday. I thought that using AddBoldedDate along
with selectionrange.start and .end would accomplish this, but it
doesn't.

Here is my code:

Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles
MonthCalendar1.DateChanged
Dim dateToday As Date = MonthCalendar1.SelectionRange.Start
Dim LastMonday As Date
SelectCase dateToday.DayOfWeek
Case DayOfWeek.Monday
LastMonday = MonthCalendar1.SelectionRange.Start
Case DayOfWeek.Tuesday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-1)
Case DayOfWeek.Wednesday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-2)
Case DayOfWeek.Thursday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-3)
Case DayOfWeek.Friday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-4)
Case DayOfWeek.Saturday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-5)
Case DayOfWeek.Sunday
LastMonday =
MonthCalendar1.SelectionRange.Start.AddDays(-6)
EndSelect

With MonthCalendar1
.SelectionRange.Start = LastMonday
.SelectionRange.End = LastMonday.AddDays(7)
for x = 0 to 6
.AddBoldedDate(LastMonday.AddDays(x))
next
End With
End Sub

Thanks,
Randy

Sep 25 '07 #3

P: n/a
Actually I've found a flaw in the case where a user selects a sunday,
it goes to the next week, but that should be easy to fix with an IIF
or whatever.

Sayonnara, Bob

Sep 25 '07 #4

P: n/a
Another flaw!!! Works pretty well in Vista but causes some display
corruption in XP...
Sep 25 '07 #5

P: n/a
That works perfectly.

For anybody who happens upon this post, the major difference (besides
that Bob's code is much more efficient) seems to be that I was using
selectionrange.start (and end) where Bob is using selectionstart and
selectionend.

Thanks, Bob!
Randy

Sep 27 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.