Results 1 to 13 of 13

Thread: [RESOLVED] Month Calendar trouble

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Location
    Surabaya, Indonesia
    Posts
    163

    Resolved [RESOLVED] Month Calendar trouble

    I have a simple code with a month calendar.

    vb Code:
    1. Dim CurrentStart As Date
    2.     Dim CurrentEnd As Date
    3.     Dim TransactDates As List(Of Date)
    4.     Protected Sub LoadMonth()
    5.         TransactDates = New List(Of Date)
    6.  
    7.         for i=1 to 10
    8.             TransactDates.Add(DateAdd(DateInterval.Day, i, TransactionMonthCalendar.SelectionRange.Start))
    9.         Next
    10.  
    11.         TransactionMonthCalendar.BoldedDates = TransactDates.ToArray
    12.     End Sub
    13.  
    14.     Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    15.         If Not DesignMode Then
    16.             CurrentStart = Today.Date
    17.             CurrentEnd = Today.Date
    18.  
    19.             LoadMonth()
    20.         End If
    21.     End Sub
    22.  
    23.     Private Sub TransactionMonthCalendar_DateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles TransactionMonthCalendar.DateChanged
    24.         If e.Start.Month <> CurrentStart.Month Or e.Start.Year <> CurrentStart.Year Then
    25.             CurrentStart = e.Start
    26.             LoadMonth()
    27.         End If
    28.  
    29.         If e.Start <> CurrentStart Or e.End <> CurrentEnd Then
    30.             CurrentStart = e.Start
    31.             CurrentEnd = e.End
    32.         End If
    33.     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..
    Check my Blog at VB Corner,Component Crafts

  2. #2
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    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.

  3. #3
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Location
    Surabaya, Indonesia
    Posts
    163

    Re: Month Calendar trouble

    Quote Originally Posted by Evil_Giraffe View Post
    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.

    Quote Originally Posted by kevininstructor View Post
    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..
    Check my Blog at VB Corner,Component Crafts

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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:
    1. Protected Sub LoadMonth()
    2.     Dim TransactDates As New List(Of Date)
    3.     Dim dt As Date = TransactionMonthCalendar.SelectionRange.Start
    4.     For i = 0 To Math.Min(dt.Day + 10, 31) - dt.Day
    5.         TransactDates.Add(dt.AddDays(i))
    6.     Next
    7.     TransactionMonthCalendar.MonthlyBoldedDates = TransactDates.ToArray
    8. End Sub
    9.  
    10. Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    11.     If Not DesignMode Then
    12.         LoadMonth()
    13.     End If
    14. End Sub
    15.  
    16. Private Sub TransactionMonthCalendar_DateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles TransactionMonthCalendar.DateChanged
    17.     ' not required
    18. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Month Calendar trouble

    Sorry that code would misbehave for months that don't have 31 days.
    Use this instead:
    vb.net Code:
    1. Protected Sub LoadMonth()
    2.     Dim TransactDates As New List(Of Date)
    3.     Dim dt As Date = DateSerial(2011, 1, TransactionMonthCalendar.SelectionRange.Start.Day)
    4.     For i = 0 To Math.Min(dt.Day + 10, 31) - dt.Day
    5.         TransactDates.Add(dt.AddDays(i))
    6.     Next
    7.     TransactionMonthCalendar.MonthlyBoldedDates = TransactDates.ToArray
    8. End Sub
    9.  
    10. Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    11.     If Not DesignMode Then
    12.         LoadMonth()
    13.     End If
    14. End Sub
    15.  
    16. '' ... This event is not required ...
    17. 'Private Sub TransactionMonthCalendar_DateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles TransactionMonthCalendar.DateChanged
    18. '
    19. 'End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Location
    Surabaya, Indonesia
    Posts
    163

    Re: Month Calendar trouble

    Quote Originally Posted by Pradeep1210 View Post
    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:
    1. Protected Sub LoadMonth()
    2.     Dim TransactDates As New List(Of Date)
    3.     Dim dt As Date = TransactionMonthCalendar.SelectionRange.Start
    4.     For i = 0 To Math.Min(dt.Day + 10, 31) - dt.Day
    5.         TransactDates.Add(dt.AddDays(i))
    6.     Next
    7.     TransactionMonthCalendar.MonthlyBoldedDates = TransactDates.ToArray
    8. End Sub
    9.  
    10. Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    11.     If Not DesignMode Then
    12.         LoadMonth()
    13.     End If
    14. End Sub
    15.  
    16. Private Sub TransactionMonthCalendar_DateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles TransactionMonthCalendar.DateChanged
    17.     ' not required
    18. 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.
    Check my Blog at VB Corner,Component Crafts

  8. #8
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Month Calendar trouble

    Can't you set that all in one go instead of doing for each month in DateChanged event?
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Location
    Surabaya, Indonesia
    Posts
    163

    Re: Month Calendar trouble

    Quote Originally Posted by Pradeep1210 View Post
    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.
    Check my Blog at VB Corner,Component Crafts

  10. #10
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Month Calendar trouble

    OK Try this:

    Create a new class:
    vb.net Code:
    1. Public Class MyMonthCalendar
    2.     Inherits MonthCalendar
    3.     Private Const WM_TIMER As Integer = &H113
    4.  
    5.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    6.         If m.Msg = WM_TIMER Then Return
    7.         MyBase.WndProc(m)
    8.     End Sub
    9. 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.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Location
    Surabaya, Indonesia
    Posts
    163

    Re: Month Calendar trouble

    Quote Originally Posted by Pradeep1210 View Post
    OK Try this:

    Create a new class:
    vb.net Code:
    1. Public Class MyMonthCalendar
    2.     Inherits MonthCalendar
    3.     Private Const WM_TIMER As Integer = &H113
    4.  
    5.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    6.         If m.Msg = WM_TIMER Then Return
    7.         MyBase.WndProc(m)
    8.     End Sub
    9. 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
    Check my Blog at VB Corner,Component Crafts

  12. #12
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Month Calendar trouble

    Quote Originally Posted by michaelrawi View Post
    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.

    Quote Originally Posted by michaelrawi View Post
    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.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Location
    Surabaya, Indonesia
    Posts
    163

    Re: Month Calendar trouble

    Quote Originally Posted by Pradeep1210 View Post
    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.
    Check my Blog at VB Corner,Component Crafts

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width