473,382 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Highlight entire week in MonthCalendar Control

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
5 8695
Any takers?

Sep 24 '07 #2
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
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
Another flaw!!! Works pretty well in Vista but causes some display
corruption in XP...
Sep 25 '07 #5
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Laguna | last post by:
Hi Gurus, I want to find the expiration date of stock options (3rd Friday of the month) for an any give month and year. I have tried a few tricks with the functions provided by the built-in...
10
by: Ty Smith via AccessMonster.com | last post by:
I noticed that the week numbers in Stephan Leban's MonthCalendar are not consistent with Microsoft Outlook (they are shifted one week forward). Is there any way I can sync these two up by changing...
3
by: michael_hk | last post by:
Hi, I am new to Windows Form programming and now have a simple Q about MonthCalendar. I want to hightlight some days in the calendar by changing the background color of these days. But I...
0
by: Patrick Bustraen | last post by:
I would like to paint a transparent color bar on a weekrow in the MonthCalender Control. This would make it possible to select a week. In Outlook 2003 the control is used in such a way, but for me...
2
by: Robert Misiak | last post by:
Hi everyone- I've done a lot of searching around on the web and I'm sure the answer to this question is no, but I'll ask anyway. Is it possible to create an inherited MonthCalendar control and...
8
by: vbmark | last post by:
I want the MonthCalendar control to return the single day selected. I have MaxSelectionCount = 1. What I get back though is this: "SelectionRange: Start: 5/5/2005 12:00:00 AM, End: 5/5/2005...
3
by: RG | last post by:
For a Windows project in VB.NET 2003: I need a Calendar that’s much larger than the MonthCalendar control in the toolbox; it needs to fill the whole screen (at least approximately ). VB...
1
by: DS | last post by:
I seem to have run into another strange anomaly with the monthCalendar control. I want to display 6 months at time with either the first half of the year (January-June) or the later half of the...
2
by: meska | last post by:
Hi all, Scenario: I have a MonthCalendar control, and DataGridView. Depending on dates displayed in MonthCalendar I want to update information from database. The Possible Solution: So I...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.