Results 1 to 4 of 4

Thread: [RESOLVED] Editing 3rd party calendar control

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Bunker Hill, WV
    Posts
    154

    Resolved [RESOLVED] Editing 3rd party calendar control

    I know I'm probably breaking protocol by asking this question here, but I'm not sure who else can help me.

    I'm trying to use a 3rd party calendar control found at http://www.codeproject.com/KB/select...hCalendar.aspx. The control is great and significzantly expands on the MS MonthCalendar control. However, I'm using VB not C# so I'm having trouble manipulating the properties of the control.

    Specifically, I'm at a loss for how to add new dates into the "Dates" property array. I currently have been pulling dates from a database using the following code:

    Code:
            Using DateItem As New Pabo.Calendar.DateItem            
    
                Try
    
                    Dim EffectiveDates As New List(Of Pabo.Calendar.DateItem)
                    Dim AppointmentDates As New DataTable
                    AppointmentDates = Me.TblGroupScheduleTableAdapter1.GetDataByDateFilter()
    
                    For Each r As DataRow In AppointmentDates.Rows
                        'My problem is here: How can I convert the existing Date format to
                        'the new DateItem format in this add statement?
                        EffectiveDates.Add(CDate(r("AppointmentDate")))
                    Next
    
                    EffectiveDates.Sort()
                    Dim MyDateArray As Pabo.Calendar.DateItem() = EffectiveDates.ToArray
    
                    Me.clndrAppointments.AddDateInfo(MyDateArray)
    
                Catch ex As Exception
                    MsgBox(ex.Message)
                    Exit Sub
    
                End Try
    
            End Using
    Here's the author's example:

    Code:
    private void FormatDates()
    {
        DateItem[] d = new DateItem[5]; 
        d.Initialize(); 
        for (int i = 0;i<5;i++)
            d[i] = new DateItem();
    
        d[0].Date = new DateTime(2005,6,3);
        d[0].BackColor1 = Color.Red;
        d[0].ImageListIndex = 3;
        d[0].Text = "Help";
        d[1].Date = new DateTime(2005,6,12);
        d[1].ImageListIndex = 2;
        d[2].Date = new DateTime(2005,6,16);
        d[2].BackColor1 = Color.LightBlue;
        d[2].ImageListIndex = 8;
        d[3].Date = new DateTime(2005,6,18);
        d[3].BackColor1 = Color.GreenYellow;
        d[3].ImageListIndex = 1;
        d[3].Text = "NorDev";
        d[4].Date = new DateTime(2005,6,22);
        d[4].ImageListIndex = 1;
        d[4].Text = "Cebit";
    
        monthCalendar1.AddDateInfo(d);
    }
    I guess I have one other concern, also. Because I'm using a "Using" block (which I've never done before) will I lose these dates from the array once the block ends and the programs discards the new data type?

    I know this should be posted on the author's site, and I've done that, but no one seems to be monitoring it anymore. I just need a nudge in the right direction here.

    Thanks from anyone who can help.
    Last edited by ssmith147; May 27th, 2008 at 09:43 AM.

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Editing 3rd party calendar control

    Ok, the "DateItem" class looks like it has 4 properties:
    The "Date", which is the date you want something to happen (12/25/2008).
    The "Text", which is the text that'll appear in the calendar box ("Christmas Day").
    The "BackColor1", which is probably the color that you want that dat to appear on the calendar (Color.Red).
    And the "ImageListIndex", where, if the control is linked to an ImageList filled with pictures, will let you choose which picture to put in that calendar cell.

    So... knowing that just from looking over the example... sounds like all you need to do is make a list of DateItem, and add a new one for each date you got:

    Code:
            Try
    
                Dim EffectiveDates As New List(Of Date)
                Dim CalendarDates As New List(Of DateItem)
                Dim AppointmentDates As New DataTable
                Dim di As DateItem
                Dim d As Date
    
                'Use SQL query to pull distinct dates from the database
                AppointmentDates = Me.TblGroupScheduleTableAdapter1.GetDataByDateFilter()
    
                For Each r As DataRow In AppointmentDates.Rows
                    d = CDate(r("AppointmentDate"))
                    EffectiveDates.Add(d)
                    di = New DateItem
                    di.Date = d
                    di.BoldedDate = True
                    CalendarDates.Add(di)
                Next
    
                EffectiveDates.Sort()
                Dim MyDateArray As Date() = EffectiveDates.ToArray
    
                'Set ms calendar control dates to bold
                Me.Calendar.AddDateInfo(CalendarDates)
    
            Catch ex As Exception
                MsgBox(ex.Message)
                Exit Sub
            End Try
    Last edited by Jenner; May 27th, 2008 at 09:47 AM.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Bunker Hill, WV
    Posts
    154

    Re: Editing 3rd party calendar control

    I tried your code, but I rtan into the same problem I was facing before- the editor didn't recognize the user data type. After speaking with someone else, I learned that I could import the controll's data type by using the "Imports" statement. I had never used it before, and I wasn't even sure what it was used for until now. Once I placed that at the top of the code, however, everything else started making more sense. Here's the code I ended up with in case it's usful to anyone else:

    Code:
        Imports Pabo.Calendar
    
        Public Class Trial2
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim now As DateTime = DateTime.Now
            Dim EventDate() As DateTime = GetEventDates(now.Month, now.Year)
            Dim EventDays As New List(Of DateItem)()
    
            For Each EventDateTime As DateTime In EventDate
                Dim EventDay As New DateItem()
                EventDay.Date = EventDateTime
                EventDay.BackColor1 = Color.Yellow
                EventDay.BoldedDate = True
                EventDay.Text = "Group Scheduled"
                EventDays.Add(EventDay)
            Next
    
            clndrAppointments.AddDateInfo(EventDays.ToArray())
        End Sub
    
        Private Function GetEventDates(ByVal month As Integer, ByVal year As Integer) As DateTime()
            Dim EventDates As New List(Of Date)
            Dim AppointmentDates As New DataTable
            AppointmentDates = Me.TblGroupScheduleTableAdapter1.GetDataByDateFilter()
    
            For Each r As DataRow In AppointmentDates.Rows
                EventDates.Add(CDate(r("AppointmentDate")))
            Next
    
            EventDates.Sort()
    
            Return EventDates.ToArray()
    
    End Sub
    
    End Class
    The date sbeing pulled from the database are static in this code- there's no way to change the parameters of the SQL query. Adding parameters would be a simple process, though.

    I plan to catch the MonthChange event and use that to specifiy the first and last dates showing on the control, and pass those back to a new query as @StartDate and @EndDate. I think I have to flush the existing datesin the array before doing this, but according to the author's article doing so is a built in method. This should allow users to scroll through the months and always see accurate information while keeping the size of the Dates array to a minimum.

    Jenner, thanks for your help on this. Some of your syntax helped me figure out setting parameters for the final array.

  4. #4
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: [RESOLVED] Editing 3rd party calendar control

    Yea, "Imports" just saves on typing.

    If you take out the Imports line, then you'd need to type:
    Dim di As Pabo.Calendar.DateItem

    as opposed to:
    Dim di as DateItem
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

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