Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Timetable, Adding days problem (Read 4173 times)
Joona
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Nov 7th, 2012
Timetable, Adding days problem
Nov 7th, 2012 at 7:46pm
Print Post  
For some reason when i try to add days to datecollection in timetable settings, it wont work. For example i add 7 days to date collection. It only takes last one of them. Heres my code for doing it. Wheres the problem?

        For isa As Integer = 0 To Calendar1.TimetableSettings.Dates.Count - 1
            Calendar1.TimetableSettings.Dates.RemoveAt(isa)
        Next
        Dim dtNow As Date = Date.Now.Date

        Calendar1.TimetableSettings.Dates.Capacity = 10

        Dim nowdayofweek As Integer = dtNow.DayOfWeek

        Dim weekStartDate, weekEndDate As Date

        weekStartDate = DateAdd("d", 0 - dtNow.DayOfWeek,    dtNow)

        weekEndDate = DateAdd("d", 6 - dtNow.DayOfWeek, dtNow)
        Dim loopDate As New TimetableDate
        loopDate.Value = weekStartDate
        Dim index As Integer = 0


This is the code that should add dates to collection. other code is just to get start and end date from current week so i can add all days of this week to collection.


        While loopDate.Value <= weekEndDate
            Calendar1.TimetableSettings.Dates.Add(loopDate)
            loopDate.Value = loopDate.Value.AddDays(1)
        End While


  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Timetable, Adding days problem
Reply #1 - Nov 8th, 2012 at 7:01am
Print Post  
Hi,

The code is not working because TimetableDate is a reference type and when you just modify the Value property of loopDate and try to re-add that instance to the Dates collection, it's already there, so Add actually exits without adding the item. You have to create new instances of the TimetableDate class and add those to the collection. Your snippet can be modified to something like this:

Code
Select All
Calendar1.TimetableSettings.Dates.Clear()

Dim nowdayofweek As Integer = dtNow.DayOfWeek

Dim weekStartDate, weekEndDate As Date

weekStartDate = DateAdd("d", 0 - dtNow.DayOfWeek, dtNow)
weekEndDate = DateAdd("d", 6 - dtNow.DayOfWeek, dtNow)

While True
  If weekStartDate > weekEndDate Then
    Exit While
  End If
  ' Creates a new instance of the TimetableDate class and
  ' adds it to the Dates collection
  Calendar1.TimetableSettings.Dates.Add(New TimetableDate(weekStartDate))
  weekStartDate += TimeSpan.FromDays(1)
End While
 



Regards,
Lyubo
  
Back to top
 
IP Logged
 
Joona
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Nov 7th, 2012
Re: Timetable, Adding days problem
Reply #2 - Nov 9th, 2012 at 7:52am
Print Post  
Well that solved my problem, Thank you very much Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint