|
-
Jan 27th, 2011, 09:48 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Month Calendar trouble
I have a simple code with a month calendar.
vb Code:
Dim CurrentStart As Date
Dim CurrentEnd As Date
Dim TransactDates As List(Of Date)
Protected Sub LoadMonth()
TransactDates = New List(Of Date)
for i=1 to 10
TransactDates.Add(DateAdd(DateInterval.Day, i, TransactionMonthCalendar.SelectionRange.Start))
Next
TransactionMonthCalendar.BoldedDates = TransactDates.ToArray
End Sub
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not DesignMode Then
CurrentStart = Today.Date
CurrentEnd = Today.Date
LoadMonth()
End If
End Sub
Private Sub TransactionMonthCalendar_DateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles TransactionMonthCalendar.DateChanged
If e.Start.Month <> CurrentStart.Month Or e.Start.Year <> CurrentStart.Year Then
CurrentStart = e.Start
LoadMonth()
End If
If e.Start <> CurrentStart Or e.End <> CurrentEnd Then
CurrentStart = e.Start
CurrentEnd = e.End
End If
End Sub
The code should work like this: Every time i moved the month, it should make 10 bold days in that month.
It works fine in VS 2010 and VS2008. The problem is, after I copy (compile with debug/release) to client computers, it start made trouble. On Win 7 OS, the calendar render nothing if i press the left or right arrow, then it suddenly go to january 1753. On Win XP OS, I can't even press left or right arrow button to change month. If I press that left and right button, it will keep moving forward without stopping.
I hope anyone can have some solutions to me. I already have this bug for about a few months and still don't have any clue on how to solve it..
Thanks n regards..
-
Jan 27th, 2011, 05:14 PM
#2
Re: Month Calendar trouble
What sort of control is TransactionMonthCalendar?
Do your clients have different regional settings to your development computer perhaps? That would be a likely suspect for any oddity with calendar logic.
-
Jan 27th, 2011, 05:52 PM
#3
Re: Month Calendar trouble
There are some issues with the calendar control which revolve around a common control outside of the calendar control which another user had a different issue than you but Microsoft's response was they knew about it but currently there was no fix in place. This was months ago and not sure if the status has changed.
Go to the last few post in this thread and look at the links that have connect in them
http://www.vbforums.com/showthread.p...DateTimePicker
-
Jan 27th, 2011, 09:22 PM
#4
Thread Starter
Addicted Member
Re: Month Calendar trouble
 Originally Posted by Evil_Giraffe
What sort of control is TransactionMonthCalendar?
Do your clients have different regional settings to your development computer perhaps? That would be a likely suspect for any oddity with calendar logic.
It's Month Calendar. My clients has default settings just like my development computers. I already tested with debug/release version in my computer too (without using VS), and it appears that I produce the bug too.
 Originally Posted by kevininstructor
There are some issues with the calendar control which revolve around a common control outside of the calendar control which another user had a different issue than you but Microsoft's response was they knew about it but currently there was no fix in place. This was months ago and not sure if the status has changed.
Go to the last few post in this thread and look at the links that have connect in them
http://www.vbforums.com/showthread.p...DateTimePicker
So its a bug from microsoft then? Not my coding... Maybe I should use other than month calendar. Too bad, I like its functionality..
-
Jan 28th, 2011, 03:10 AM
#5
Re: Month Calendar trouble
From what I understand, you want to highlight the next 10 days in the month calendar for every month.
If that's right then, I think what you really need is the MonthlyBoldedDates instead of BoldedDates
And then you don't need the TransactionMonthCalendar_DateChanged event handler and the tracking of last selected month etc.
So only this much:
vb.net Code:
Protected Sub LoadMonth() Dim TransactDates As New List(Of Date) Dim dt As Date = TransactionMonthCalendar.SelectionRange.Start For i = 0 To Math.Min(dt.Day + 10, 31) - dt.Day TransactDates.Add(dt.AddDays(i)) Next TransactionMonthCalendar.MonthlyBoldedDates = TransactDates.ToArray End Sub Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not DesignMode Then LoadMonth() End If End Sub Private Sub TransactionMonthCalendar_DateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles TransactionMonthCalendar.DateChanged ' not required End Sub
-
Jan 28th, 2011, 03:18 AM
#6
Re: Month Calendar trouble
Sorry that code would misbehave for months that don't have 31 days.
Use this instead:
vb.net Code:
Protected Sub LoadMonth() Dim TransactDates As New List(Of Date) Dim dt As Date = DateSerial(2011, 1, TransactionMonthCalendar.SelectionRange.Start.Day) For i = 0 To Math.Min(dt.Day + 10, 31) - dt.Day TransactDates.Add(dt.AddDays(i)) Next TransactionMonthCalendar.MonthlyBoldedDates = TransactDates.ToArray End Sub Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not DesignMode Then LoadMonth() End If End Sub '' ... This event is not required ... 'Private Sub TransactionMonthCalendar_DateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles TransactionMonthCalendar.DateChanged ' 'End Sub
-
Jan 28th, 2011, 06:39 AM
#7
Thread Starter
Addicted Member
Re: Month Calendar trouble
 Originally Posted by Pradeep1210
From what I understand, you want to highlight the next 10 days in the month calendar for every month.
If that's right then, I think what you really need is the MonthlyBoldedDates instead of BoldedDates
And then you don't need the TransactionMonthCalendar_DateChanged event handler and the tracking of last selected month etc.
So only this much:
vb.net Code:
Protected Sub LoadMonth()
Dim TransactDates As New List(Of Date)
Dim dt As Date = TransactionMonthCalendar.SelectionRange.Start
For i = 0 To Math.Min(dt.Day + 10, 31) - dt.Day
TransactDates.Add(dt.AddDays(i))
Next
TransactionMonthCalendar.MonthlyBoldedDates = TransactDates.ToArray
End Sub
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not DesignMode Then
LoadMonth()
End If
End Sub
Private Sub TransactionMonthCalendar_DateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles TransactionMonthCalendar.DateChanged
' not required
End Sub
Indeed. My sample code is to highlight 10 days in every month. But what I want to show is how to produce the bug with simple code. My real case is that I want to bold a few days which are different each month because I look up on the database. So date changed event is still required to determine what days need to be bold on month that currently display by load it on the database..
Thanks and regards.
-
Jan 28th, 2011, 06:47 AM
#8
Re: Month Calendar trouble
Can't you set that all in one go instead of doing for each month in DateChanged event?
-
Jan 28th, 2011, 09:38 AM
#9
Thread Starter
Addicted Member
Re: Month Calendar trouble
 Originally Posted by Pradeep1210
Can't you set that all in one go instead of doing for each month in DateChanged event?
That would be impossible. In my real case, the bold dates are transactions that happened in those month who pointed by user. Transactions are growing each day, so there's no way I would bold all dates from beginning of transactions.
-
Jan 28th, 2011, 10:04 AM
#10
Re: Month Calendar trouble
OK Try this:
Create a new class:
vb.net Code:
Public Class MyMonthCalendar Inherits MonthCalendar Private Const WM_TIMER As Integer = &H113 Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg = WM_TIMER Then Return MyBase.WndProc(m) End Sub End Class
After compiling the project, you will see a new component named MyMonthCalendar in the toolbox. Replace your calendar control with this one and see if it works.
-
Jan 28th, 2011, 10:28 AM
#11
Thread Starter
Addicted Member
Re: Month Calendar trouble
 Originally Posted by Pradeep1210
OK Try this:
Create a new class:
vb.net Code:
Public Class MyMonthCalendar
Inherits MonthCalendar
Private Const WM_TIMER As Integer = &H113
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_TIMER Then Return
MyBase.WndProc(m)
End Sub
End Class
After compiling the project, you will see a new component named MyMonthCalendar in the toolbox. Replace your calendar control with this one and see if it works.
Thank you very much. It works like charm. Playing with WndProc seems way beyond my knowledge.. ..
Anyway, I still has 2nd problem with this calendar. If u try to change the year (i.e. click the year of the calendar then press up or down), it will go directly to January 1753. Do you know how to resolve this?
thanks and regards
-
Jan 28th, 2011, 02:15 PM
#12
Re: Month Calendar trouble
 Originally Posted by michaelrawi
Thank you very much. It works like charm. Playing with WndProc seems way beyond my knowledge..  ..
Using process viewer, I found that the event was firing second time due WM_TIMER message. So I just override the WndProc to ignore that message.
I have no idea where that event is being legitimately used. So, though it may have solved your current problem, it might start causing some other problems where it was legitimately used. So keep a watch for any unexpected behavior and report back if you find anything going weird.
 Originally Posted by michaelrawi
Anyway, I still has 2nd problem with this calendar. If u try to change the year (i.e. click the year of the calendar then press up or down), it will go directly to January 1753. Do you know how to resolve this?
Though I don't have much idea about that, according to the forum norms we keep one question tied to one thread so that others facing similar problems can benefit too. Since your original question is answered, can you please mark this thread resolved, and start a new thread for this and PM me the link?
Doing so will also attract more people towards that thread who are not watching this thread, and someone might suggest you a better solution. So it is in your interest too.
-
Jan 28th, 2011, 08:27 PM
#13
Thread Starter
Addicted Member
Re: Month Calendar trouble
 Originally Posted by Pradeep1210
Though I don't have much idea about that, according to the forum norms we keep one question tied to one thread so that others facing similar problems can benefit too. Since your original question is answered, can you please mark this thread resolved, and start a new thread for this and PM me the link?
Doing so will also attract more people towards that thread who are not watching this thread, and someone might suggest you a better solution. So it is in your interest too.
Thread marked as resolved. I will post this case sooner. Thanks for your suggestion.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|